string类实现的运算符重载
连接:+
比较:==, !=, <=, >=, <, >.比较是以字典序进行比较
下标:[], 访问指定字符,可以作为左值
赋值:=, +=等, 右操作数可以是字符串,字符,C字符串,字符数组
字典序
按英文单词在字典中的顺序,后出现的大(大写字母比小写字符先出现)
string类的成员函数
length()返回字符串长度
c_str()返回类型为const char*的C风格字符串
find(str)寻找首个等于给定字符序列的子串,可以指定开始位置,find(str, 3)即从第四个位置开始查找
replace替换
append(str)后接上str,append(count, str)后接上count个str(等效于+=str)
insert(index, str)在index位置插入str,insert(index, count, str)在index位置插入count个str
erase(index)删除index的字符,erase(index, count)删除index开始的count个字符
clear()清空
substr(index, count)返回index开始的count个字符
compare(a, b)比较,返回-1,0,1(等效于>)
copy(aim, index, count)将自串赋值给目标对象(等效于=)
swap(string other)交换内容