<span style="font-size:14px;">构造函数 <span style="white-space:pre"> </span>说明</span>
<span style="font-size:14px;">string str<span style="white-space:pre"> </span>默认构造函数,创建一个空的string对象,名为str</span>
<span style="font-size:14px;">string str("sample"); <span style="white-space:pre"> </span>创建一个string对象,其中含有数据sample</span>
<span style="font-size:14px;">string str(a_string);<span style="white-space:pre"> </span>创建一个名为str的一个string对象,它是a_string的一个副本,a_string是</span>
<span style="font-size:14px;"><span style="white-space:pre"> </span>string类的一个对象</span>
<span style="font-size:14px;">
</span>
<span style="font-size:14px;">元素访问(取值器--accessors)</span>
<span style="font-size:14px;">str[i]<span style="white-space:pre"> </span>返回对str中的索引i处的那个字符的一个读/写引用。不用检查非法索引</span>
<span style="font-size:14px;">str.at(i)<span style="white-space:pre"> </span>返回对str中的索引i处的那个字符的一个读/写引用,这个str[i]相同,但这个版本</span>
<span style="font-size:14px;"><span style="white-space:pre"> </span>会检查非法索引</span>
<span style="font-size:14px;">str.substr(position,length)<span style="white-space:pre"> </span>返回调用对象(也就是str)的一个子字符串。子字符串始于position,含有length</span>
<span style="font-size:14px;"><span style="white-space:pre"> </span>个字符</span>
<span style="font-size:14px;">
</span>
<span style="font-size:14px;">赋值/修改</span>
<span style="font-size:14px;">str1 = str2;<span style="white-space:pre"> </span>将str1初始化成str2的数据</span>
<span style="font-size:14px;">str1 += str2;<span style="white-space:pre"> </span>str2的字符数据连接到str1的尾部</span>
<span style="font-size:14px;">str.empty()<span style="white-space:pre"> </span>如果str是空字符串,返回true,否则返回false</span>
<span style="font-size:14px;">str1 + str2<span style="white-space:pre"> </span>返回一个字符串,它将str2的字符串连接到str1的数据尾部</span>
<span style="font-size:14px;">str.insert(pos,str2)<span style="white-space:pre"> </span>将str2插入str的位置pos处</span>
<span style="font-size:14px;">str.erease(pos,len)<span style="white-space:pre"> </span>移除长度为len的子字符串,从位置pos处开始</span>
<span style="font-size:14px;">
</span>
<span style="font-size:14px;">比较</span>
<span style="font-size:14px;">str1 == str2 str1 != str2<span style="white-space:pre"> </span>比较相等还是不等;返回布尔值类型</span>
<span style="font-size:14px;">str1 < str2 str1 > str2<span style="white-space:pre"> </span>这4个比较都是基于词典顺序的比较</span>
<span style="font-size:14px;">str1 <= str2 str1 >= str2</span>
<span style="font-size:14px;">
</span>
<span style="font-size:14px;">查找</span>
<span style="font-size:14px;">str.find(str1)<span style="white-space:pre"> </span>返回str1在str中首次出现时的索引</span>
<span style="font-size:14px;">str.find(str1,pos)<span style="white-space:pre"> </span>返回str1在str中首次出现时的索引,从位置pos处开始查找</span>
<span style="font-size:14px;">str.find_first_of(str1,pos)<span style="white-space:pre"> </span>返回str1的任何字符在str中首次出现时的索引,从位置pos处开始查找</span>
<span style="font-size:14px;">str.find_firsr_not_of(str1,pos)<span style="white-space:pre"> </span>返回不属于str1的任何字符在str中首次出现时的索引,从位置pos处开始查找</span>