【c++】string字符串拼接的三种方式
#include<iostream>#include<cstring>#include<sstream>using namespace std;string a = "hello ";string b = "world!";string f1(){return a + b;}string f2(){string c;c.append...
文章共377字 · 阅读需要大约2分钟
一键AI生成摘要,助你高效阅读
问答
·
#include<iostream>
#include<cstring>
#include<sstream>
using namespace std;
string a = "hello ";
string b = "world!";
string f1(){
return a + b;
}
string f2(){
string c;
c.append(a + b);
/*or
c.append(a);
c.append(b);
*/
return c;
}
string f3(){
stringstream ss;
ss<<a<<b;
return ss.str();
}
int main(){
//+
cout << f1() <<endl;
//append
cout << f2() << endl;
//sstream
cout << f3() << endl;
return 0;
}
运行结果
更多推荐
已为社区贡献1条内容
所有评论(0)