当前位置:网站首页>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)
其他形式的字符串字面值(有待补充)
边栏推荐
猜你喜欢
随机推荐
【SemiDrive源码分析】【MailBox核间通信】47 - 分析RPMSG_IPCC_RPC 方式 单次传输的极限大小 及 极限带宽测试
Do you think border-radius is just rounded corners?【Various angles】
转:管理是对可能性的热爱,管理者要有闯进未知的勇气
TSF微服务治理实战系列(一)——治理蓝图
Towards Real-Time Multi-Object Tracking (JDE)
C Expert Programming Chapter 4 The Shocking Fact: Arrays and pointers are not the same 4.2 Why does my code not work
The idea setting recognizes the .sql file type and other file types
符号表
少年成就黑客,需要这些技能
C Expert Programming Chapter 4 The Shocking Fact: Arrays and Pointers Are Not the Same 4.5 Other Differences Between Arrays and Pointers
[Skill] Using Sentinel to achieve priority processing of requests
[SemiDrive source code analysis] [MailBox inter-core communication] 47 - Analysis of RPMSG_IPCC_RPC mode limit size of single transmission and limit bandwidth test
C Expert Programming Chapter 4 The Shocking Fact: Arrays and pointers are not the same 4.1 Arrays are not pointers
What are the functions of mall App development?
What is the salary of a software testing student?
【21天学习挑战赛】直接插入排序
某母婴小程序加密参数解密
解决错误:npm WARN config global `--global`, `--local` are deprecated
QT 如何识别文件的编码格式
C Expert Programming Chapter 5 Thinking about Linking 5.2 Advantages of Dynamic Linking









