1、查找
string str="jsdjkssk";
int pos=str.find("js"); //find从左往右找,rfind从右往左找
cout<<pos;
pos=0; //pos为js第一次出现的位置,如果没有,则输出-1;
2、替换
str.replace(从哪个位置起,多少个字符,“smsd”)
str,replace(1,3,sgg)
3.比较
string str1="hello"
string str2="hello";
str1.compare(str2)==0
逐个比较每个字母的大小
4、读写
①str[i] 或者 str.at(i)
②str[0]='x' 或者 str.at(1)='x'
5.插入和删除
string str="hello";
插入 str.insert(1,"111")
h111ello;
删除 str.erase(1,3)
hello;
6、截取其中的一部分字串
string str="abcdefg";
string subStr=str.subStr(1,3)
bcd