C++ string字符串拼接

string s1 = "Hello ";
string s2 = "World!";
s1.append(s2);
cout << s1 << endl;

string s3 = "Hello ";
string s4 = "Hello World!";

s3.append(s4,6,5);//从s4的第六位(0位开始数)开始的连续5位--World,即s3+"World"
cout << s3 << endl;//

string s5 = "Hello ";
//将10个A拼接到字符串s5的后面
s5.append(10,'A');
cout << s5 << endl;

string s6 = s1 + s2;
cout << s6 <

C++ string字符串拼接_第1张图片

你可能感兴趣的:(C++)