string可以拼接, 但遇到串和整数拼接, 就比较蛋疼, 还是stringstream好, 但stringstream有clear之后, 我们已经说过了, 所以要注意。

       最近用stringstream, 真的是太爽了, 看看:

 

#include <iostream>
#include <sstream>
using namespace std;

int main()
{
	stringstream ss;
	char szTest[] = "abc";
	ss  << "hello" << 123 << szTest;
				
	cout << ss.str() << endl;
	return 0;
}

      结果:hello123abc
 

 

 


本文转载:CSDN博客