stringstream快速实现String和int之间的转换

需要包含头文件”sstream”

 1 #include 
 2 #include <string>
 3 #include 
 4 using namespace std;
 5 int string2int(string str){
 6     int num;
 7     stringstream sstream;
 8     sstream << str;
 9     sstream >> num;
10     return num;
11 }
12 string int2string(int num){
13     string re;
14     stringstream sstream;
15     sstream << num;
16     return sstream.str();
17 }

 

转载于:https://www.cnblogs.com/liangf27/p/9356849.html

你可能感兴趣的:(stringstream快速实现String和int之间的转换)