string的增很简单,直接用”+“,”+=“操作符,可以方便的对字符串进行添加
int main() {
string s1;
string s2;
s1 = "abc";
s2 = "abc";
cout << s1 + s2 << endl;
return 0;
}
//输出 abcabc
append()操作
int main() {
string s1;
string s2;
s1 = "str1";
s2 = "str2";
s1.append("123"); //直接添加字符串至尾部
cout << s1 << endl;
s1.append("1230", 2); //从参数字符串起始位置开始添加2个字符到s1
cout << s1 << endl;
s1.append(s2, 0, 1); //把s2的区间[0,1)的字符添加至s1
cout << s2 << endl << s1 << endl;
return 0;
}
append是把参数添加至字符串的尾部,参数字符串可以是string,也可以是c_str,在参数字符串的后面可以参数字