Ubuntu下C++ string转int:std::stoi()函数使用教程

在Ubuntu系统下,可以使用std::stoi函数将C++的string类型转换为int类型。

#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
Ubuntu下C++ string转int:std::stoi()函数使用教程

原文地址: https://www.cveoy.top/t/topic/pr91 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录