C++ 字符串转int

1.C++风格的流

include;
stringstream stream;
int number = 0;
string text("13");
stream << text;
stream >> number ;
stream.clear();//转换后字符串还保留在流中,需使用手动清空

2.C风格的atoi()函数

int number = 0;
string text = "13";
number = atoi(text.c_str());

参考:https://www.cnblogs.com/gaobw/p/7070622.html

https://blog.csdn.net/weierqiuba/article/details/66473060?ticket=ST-478290-hLIgAcBHRhvq1i7zEnCb-passport.csdn.net


你可能感兴趣的:(C++)