c++ stl中的stringstream可以方便的将各种类型值转换成string。
头文件 #include <sstream>
样例:
#include <iostream> #include <sstream> using namespace std; int main() { int a = 10; long long b = 11; string c = "12"; double d = 0.13; short e = 14; char f = 'o'; stringstream s; s<<a<<' '<<b<<' '<<c<<' '<<d<<' '<<e<<' '<<f; cout<<s.str()<<endl; return 0; }