当前位置:网站首页>string类简介
string类简介
2022-08-04 05:16:00 【叽里呱啦呱】
简介: IOS/ANSI C++标准通过添加string类拓展了C++库,因此现在可以用string类型的变量(c++中称为对象)而不仅是字符数组来储存字符串,string类使用起来比数组简单,同时也提供了将字符串组作为一种数据类型的表示方式。
#要使用string类,必须要在程序中包含头文件string,string类位于命名空间std中。
使用string对象的方式与字符数组相同,但是类设计让程序可以自动处理string的大小,因此与数组相比string对象也更加安全
赋值,拼接,附值
可以像普通变量一样赋值,但是数组不能
string类简化了子字符串的合并操作可以使用运算符+将两个string对象合并起来,还可以用运算符+=将字符串附加到string对象的末尾
string类的其他操作
确定字符串的长度name.size(),c++string对象使用对象名和句点运算符来指出使用哪个字符串
输出均与字符数组一样,但整行输入有些区别,是这样表示的getline(cin,str)
其他形式的字符串字面值(有待补充)
边栏推荐
- 编程大杂烩(四)
- Shocked, 99.9% of the students didn't really understand the immutability of strings
- C Expert Programming Chapter 5 Thinking about Chaining 5.6 Take it easy --- see who's talking: take the Turning quiz
- The symbol table
- 少年成就黑客,需要这些技能
- ADC噪声全面分析 -03- 利用噪声分析进行实际设计
- flink cdc一启动,源端Oracle那台服务器的CPU就飙升到80%以上,会是啥原因呢?
- sql server如何得到本条记录与上一条记录的差异,即变动值
- C Expert Programming Chapter 4 The Shocking Fact: Arrays and pointers are not the same 4.2 Why does my code not work
- 有趣的 Kotlin 0x0E:DeepRecursiveFunction
猜你喜欢
随机推荐
Redis common interview questions
深度学习21天——卷积神经网络(CNN):实现mnist手写数字识别(第1天)
一个对象引用的思考
C专家编程 第5章 对链接的思考 5.6 轻松一下---看看谁在说话:挑战Turning测验
【一步到位】Jenkins的安装、部署、启动(完整教程)
Hangdian Multi-School-Slipper- (tree map conversion + virtual point mapping)
力扣:746. 使用最小花费爬楼梯
share总结
Large chain best freight d audit with what software?What are the functions?
C专家编程 第5章 对链接的思考 5.2 动态链接的优点
力扣:96.不同的二叉搜索树
【JS】js给对象动态添加、设置、删除属性名和属性值
OpenGL绘制圆
C专家编程 第4章 令人震惊的事实:数组和指针并不相同 4.1 数组并非指针
BFC、IFC、GFC、FFC概念理解、布局规则、形成方法、用处浅析
震惊,99.9% 的同学没有真正理解字符串的不可变性
商城系统APP如何开发 都有哪些步骤
2022 software test interview questions The latest ByteDance 50 real interview questions, 15k have been won after brushing, with explanation + Q&A
Turn: Management is the love of possibility, and managers must have the courage to break into the unknown
Introduction and application of go module