C++中的string用法

来源:互联网 发布:我的世界起床战争端口 编辑:程序博客网 时间:2024/06/05 03:37

  最近编程的时候,老会遇到string类型的字符串,但偏偏自己的记性不太好!所以就自己总结了

一下string类型的常用用法,有错误的,欢迎指正评论!


string  s1="hello" string  s2("world")两种初始化的方法string  s3 = s1 + s2   :string s1和string s2 合并成string s3 的几种方式 string  s4="hello"+s2;string  s5="hello"+s2+"world"string  s6="hello"+"world":这种合并的方式是错的,必须要有string类型的变量才行 


下面是string类型使用的函数

string类型的函数  s.empty()  函数的作用是判断s是否为空串,若是则返回true,否则返回false  s.size()   返回s中字符的个数  s[n]     返回s中位置为n的字符,位置从零开始 

我想到了更多在补充!






0 0