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。
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