stringstream是一个特殊的流,需要加头文件#include,下文中,<<表示把变量,字符串都塞到用stringstream定义的ret变量中,然后用ret.str()进行转化,这样就能得到想要的字符串了。
#include<sstream>
#include<iostream>
#include<Windows.h>
#include<string>
using namespace std;
int main(void) {
string name = "唐三";
int power = 10000;
int age = 23;
stringstream ret;
ret << name << "-男-实力(" << power << ")-年龄(" << age << ")" << endl;
cout << ret.str() << endl;
system("pause");
return 0;
}