stoi

将字符序列转换为整数。

int stoi(
    const string& _Str, 
    size_t *_Idx = 0,
    int _Base = 10
);
int stoi(
    const wstring& _Str, 
    size_t *_Idx = 0,
    int _Base = 10
);

返回值

整数值。

参数

Parameter

说明

_Str

将转换的字符序列。

_Idx

包含第一个没有重字符的索引返回。

_Base

使用的数基。

备注

函数 stoi 将字符序列。_Str 的转换类型 int 的值并返回值。例如,那么,当通过字符序列“10 ",stoi 返回的值为整数10。

stoi 行为类似于单字节字符的功能 strtol,在调用提供一种 strtol(_Str.c_str(), _Eptr, _Base)时,_Eptr 是内部一的对象传递给函数;或宽字符的 wcstol,在调用以类似方式,wcstol(Str.c_str(), _Eptr, _Base)。有关更多信息,请参见 strtol, wcstol, _strtol_l, _wcstol_l

如果 _Str.c_str() == *_Eptr,stoi 引发类型 invalid_argument对象。如果这样的调用将设置 errno,或者,如果返回值将不能表示为类型 int对象,该对象将引发类型 out_of_range对象。否则,因此,如果 _Idx 不是null指针,函数在 *_Idx存储 *_Eptr - __Str.c_str()。

要求

标头: <string>

命名空间: std

请参见

参考

string (<string>)

wstring

<string>