string 类中常用的操作包括下标访问、+= 运算符、遍历及迭代器。
push_back 和 append
push_back:尾插一个字符 append:尾插一个 string 对象或者是常量字符串
int main() {
string s("hello world");
s.push_back('x'); // hello worldx
s.append("yyy"); // hello worldyyy
return 0;
}
insert
insert(0, "hello world"):第一个参数表示 0 位置,第二个参数表示插入的字符串 insert(0, 1, ch):参数一:下标,参数二:插入字符的个数,参数三:要插入的字符 insert(s.begin(), ch):迭代器区间的头插
int main() {
string s("hello world");
s.insert(0, "hello r"); // hello rhello world
s.insert(10, "zzz"); // hello worlzzzd
char ch = 'a';
s.insert(0, 1, ch); // ahello world
s.insert(s.begin(), ch); // aahello world
// 在 10 下标位置插入 p
s.insert(0, );
s.(s.(), ch);
cout << s << endl;
;
}


