1. +
str = str + 'a';
str = str + "abc";
直接对str操作,效率高:
str += 'a';
str += "abc";
2. push_back()函数
str.push_back('y');
注意:该函数只能在字符串后面添加字符
3. append()函数
-
直接添加
string s1="He is"; s1.append(" Tom");
-
添加字符串的字串
string s2="Where is Jacky"; s1.append(s2,8,6);
-
迭代器
string s3="so strong"; s1.append(s3.begin()+2,s3.end());
-
添加字符串的前n个字符
s1.append(s2,3);
-
添加n个重复字符
s1.append(7,'y');
参考:
https://blog.csdn.net/weixin_34132725/article/details/109293031