stringstream对象可以安全的实现string类型和常用数据(int,double, char etc.)的转换。
#include <iostream>
#include <string>
#include <sstream>
int main()
{
int i = 7;
double d = 1.234;
char c = 'A';
std::string s = "hello";
char* pchar = "world";
std::stringstream p;
p << i;
p << d;
p << c;
p << s;
p << pchar;
std::string p_start = "p";
p_start += p.str();
std::cout << position_start << std::endl;
}
输出结果:p71.234Ahelloworld