C++ 将字符串转换为整数:std::stoi 函数
您可以使用 std::stoi 函数将 std::string 转换为整数。
示例代码如下:
#include <iostream>
#include <string>
int main() {
std::string str = '12345';
int num = std::stoi(str);
std::cout << 'The converted integer is: ' << num << std::endl;
return 0;
}
输出结果为: The converted integer is: 12345
原文地址: https://www.cveoy.top/t/topic/tvD 著作权归作者所有。请勿转载和采集!