#include< sstream> Header file A
brief description of basic usage
Convert basic data types int, double, float, long, etc. into strings
int t;
string st;
stringstream s;
t = 123;
s << t; //将数字输入到stringstream对象中
s >> st; //将stringstream对象中的数据输入到字符串中
cout << st;
Output result:
Similarly, it is also possible to convert a string to a basic data type, see the example.
double t;
string st = "1.25678";
stringstream s;
s << st; //将字符串输入到stringstream对象中
s >> t; //将stringstream对象中的数据输入到字符串中
cout << t;
Output result: