1.将int转化成string类型
#include <iostream> #include <sstream> using namespace std; int main() { stringstream ss; string s; int i=1234; ss<<i; ss>>s; cout<<s<<endl; return 0; }
2.将string类型转化成int类型
#include <iostream> #include <sstream> using namespace std; int main() { stringstream ss; string s="1234"; int i; ss<<s; ss>>i; cout<<i<<endl; return 0; }