stoi()函数——将数字字符转化位int输出·

  • **使用之前要包含头文件#include< string >
  • stoi()会对参数字符串进行范围判断,默认范围是在int的范围内[-2147483648, 2147483647]的,如果超出范围的话则会runtime error.
#include<iostream>
#include<string>
using namespace std;

int main()
{

    string str = "111111";
    int a = stoi(str);
    cout << a << endl;//输出111111
    return 0;
}
Logo

旨在为数千万中国开发者提供一个无缝且高效的云端环境,以支持学习、使用和贡献开源项目。

更多推荐