C++ string和int互相转换

int转string 

int aa = 30;
 stringstream ss;
 ss<<aa; 
 string s1 = ss.str();
 cout<<s1<<endl; // 30

 string s2;
 ss>>s2;
 cout<<s2<<endl; // 30

 

string转int

string s = "17";

 stringstream ss;
 ss<<s;

 int i;
 ss>>i;
 cout<<i<<endl; // 17

 

posted @ 2019-08-22 21:19  xd_xumaomao  阅读(2461)  评论(0编辑  收藏  举报