转自:https://www.cnblogs.com/A-Little-Nut/p/10311316.html
代码:
#include <iostream>
#include <sstream>
using namespace std;
int main()
{
//int 转 string
int number = 12;
string str;
stringstream ss;
ss << number;
ss >> str;
cout << str;
//注意,此时这个流中还留有之前流入的数据。
ss.clear(); //清楚这个流中残留的数据
//string 转 int
string str2 = "13";
int num;
ss << str2;
ss >> num;
cout << num;
return 0;
}