How do you concatenate two strings? [duplicate]

雨燕双飞 提交于 2020-01-25 03:15:07

问题


Possible Duplicate:
How do I concatenate multiple C++ strings on one line?

How would I take:

string test1 = "Hello ";
string test2 = "World!";

and concatenate them to make one string?


回答1:


How about

string test3 = test1 + test2;

Or maybe

test1.append(test2);



回答2:


You could do this:

string test3 = test1 + test2;

Or if you want to add more string literals, then :

string test3 = test1 + test2 + " Bye bye World!"; //ok

or, if you want to add it in the beginning, then:

string test3 = "Bye bye World!" + test1 + test2; //ok


来源:https://stackoverflow.com/questions/7537820/how-do-you-concatenate-two-strings

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!