在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打印出来。
上一篇:c语言switch的使用方法是什么
下一篇:python中如何取整数的某位数
C++









