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 );

返回值

整数值。

参数

参数

描述

_Str

要转换的字符序列。

_Idx

返回时包含首个未转换字符的索引。

_Base

要使用的号码基。

备注

函数 stoi 将 _Str 中字符的序列转换为 int 类型的值并返回该值。 例如,在传递字符序列“10”时,stoi 返回的值为整数 10.

当以 strtol(_Str.c_str(), _Eptr, _Base) 方式调用时,stoi 的行为方式与针对单字节字符的 strtol 函数相似,其中,_Eptr 是函数的内部对象;而当以类似的方式 wcstol(Str.c_str(), _Eptr, _Base) 调用时,其行为与针对宽字符的 wcstol 相似。 有关详细信息,请参阅strtol、wcstol、_strtol_l、_wcstol_l

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

要求

标头:<string>

命名空间: std

请参见

参考

字符串(C++ STL <字符串>)

wstring

<string>