Linux 拨号vps windows公众号手机端

c++中string转int怎么实现

lewis 9年前 (2016-10-11) 阅读数 10 #程序编程
文章标签 c++

在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打印出来。

版权声明

本文仅代表作者观点,不代表米安网络立场。

发表评论:

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

热门