编写一程序,将两个字符串连接起来,结果取代第一个字符串。要求用string方法。
#include<iostream>
#include
<string>
using namespacestd;
int main()
{
string str1,str2;
cin >> str1;
cin >> str2;
cout <<"str1:"
<< str1<<
endl;
cout <<"str2:"
<< str2<<
endl;
str1 = str1 + str2;
cout <<"contact result :"
<< str1
<<endl;
system("pause");
return 0;
}
本文介绍了一个简单的C++程序,该程序使用标准库中的string类来实现两个字符串的连接操作,并将连接后的结果存储在第一个字符串变量中。通过这个示例,读者可以了解如何使用C++标准库中的string方法进行字符串操作。
1434

被折叠的 条评论
为什么被折叠?



