c++中string转int怎么实现
lewis
2016-10-11
22次阅读
在C++中,可以使用std::stoi函数将字符串转换为整数。示例如下:
#include <iostream>
#include <string>
int main() {
std::string str = "123";
int num = std::stoi(str);
std::cout << num << std::endl;
return 0;
}
在上面的示例中,std::stoi函数将字符串"123"转换为整数123,并将其存储在变量num中。然后可以将num打印出来。

发表评论:
◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。