將字串轉換成最大的受支援不帶正負號整數類型的整數值。
語法
uintmax_t strtoumax(
const char *strSource,
char **endptr,
int base
);
uintmax_t _strtoumax_l(
const char *strSource,
char **endptr,
int base,
_locale_t locale
);
uintmax_t wcstoumax(
const wchar_t *strSource,
wchar_t **endptr,
int base
);
uintmax_t _wcstoumax_l(
const wchar_t *strSource,
wchar_t **endptr,
int base,
_locale_t locale
);
參數
strSource
以 Null 終止的待轉換字串。
endptr
停止掃描的字元指標。
base
要使用的數字基底。
locale
要使用的地區設定。
傳回值
若有的話,strtoumax 會傳回已轉換的值,或在發生溢位時傳回 UINTMAX_MAX。 如果沒有任何轉換可執行,strtoumax 會傳回 0。
wcstoumax 傳回類似 strtoumax 的值。 如果發生溢位或反向溢位,這兩個函式的 errno 都會設為 ERANGE。
如需傳回碼的詳細資訊,請參閱errno、 _doserrno_sys_errlist和 _sys_nerr。
備註
所有這些函式都會將輸入字串 strSource 轉換成 uintmax_t 整數值。
strtoumax 停止在無法辨識為數位一部分的第一個字元讀取字串 strSource 。 它可能是終止的 Null 字元,或者可能是大於或等於 base的第一個數值字元。 地區設定的 LC_NUMERIC 類別設定會決定 strSource 中的基底字元辨識。 如需詳細資訊,請參閱 setlocale和 _wsetlocale。
strtoumax 和 wcstoumax 使用目前的地區設定,_strtoumax_l 和 _wcstoumax_l 除了改用傳入的地區設定之外,其他相同。 如需詳細資訊,請參閱 Locale。
如果 endptr 不是 NULL,則會將停止掃描的字元指標儲存在 所 endptr指向的位置。 如果不能執行任何轉換 (找不到任何有效的數字或指定了無效的基底),則 strSource 的值會儲存在 endptr 所指的位置。
strtoumax 的寬字元版本是 wcstoumax,其 strSource 引數是寬字元字串。 否則,這些函式的行為相同。
一般文字常式對應
| TCHAR.H 常式 |
_UNICODE 和 _MBCS 未定義 |
_MBCS 已定義 |
_UNICODE 已定義 |
|---|---|---|---|
_tcstoumax |
strtoumax |
strtoumax |
wcstoumax |
_tcstoumax_l |
strtoumax_l |
_strtoumax_l |
_wcstoumax_l |
strtoumax 需要 strSource 指向格式如下的字串︰
[] [
whitespace{+|-}] [0[{x|X}]] []digits|letters
whitespace可能包含空格和製表符,這些字元會被忽略。
digits 是一或多個十進位數。
letters 是一或多個字母 'a' 到 'z' (或 'A' 到 'Z')。 不符合此表單的第一個字元會停止掃描。 如果 base 介於 2 到 36 之間,則會將其作為數位的基底。 如果 base 為 0,則使用由 strSource 指向的字串起始字元來判斷基底。 如果第一個字元是 '0',而第二個字元不是 'x' 或 'X',字串就會解譯為八進位整數。 如果第一個字元為 '0',而第二個字元是 'x' 或 X',則字串會解譯為十六進位整數。 如果第一個字元為 '1' 到 '9',則字串會解譯為十進位整數。 字母 'a' 到 'z' (或 'A' 到 'Z') 被指派值 10 到 35,只允許指派值小於 base 的字母。 基底範圍外的第一個字元會停止掃描。 例如,如果 base 為 0,而第一個掃描到的字元是 '0',則假設為八進位整數,且 '8' 或 '9' 字元會停止掃描。
strtoumax 允許加號 (+) 或減號 (-) 前置詞;前置減號表示傳回值是已轉換字串絕對值的兩個補碼。
需求
| 常式 | 必要的標頭 |
|---|---|
strtoumax、 、 wcstoumax、 _strtoumax_l_wcstoumax_l |
<int類型.h> |
如需相容性詳細資訊,請參閱相容性。
範例
請參閱 strtod 的範例。
另請參閱
資料轉換
地區設定
localeconv
setlocale、_wsetlocale
字串到數值函式
strtod、 、 _strtod_l、 wcstod_wcstod_l
strtoimax、 、 _strtoimax_l、 wcstoimax_wcstoimax_l
strtol、 、 wcstol、 _strtol_l_wcstol_l
strtoul、 、 _strtoul_l、 wcstoul_wcstoul_l
strtoll、 、 _strtoll_l、 wcstoll_wcstoll_l
atof、 、 _atof_l、 _wtof_wtof_l