strtoumax, _strtoumax_l, wcstoumax, _wcstoumax_l

将字符串转换为受支持的最大无符号整数类型的整数值。

语法

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。 这可能是终止空字符,也可能是大于或等于 base 的第一个数字字符。 区域设置的 LC_NUMERIC 类别设置确定 strSource 中的基数字符的识别。 有关详细信息,请参阅 setlocale_wsetlocalestrtoumaxwcstoumax 使用当前区域设置;_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 <inttypes.h>

有关兼容性的详细信息,请参阅 兼容性

示例

请参阅 strtod 的示例。

另请参阅

数据转换
区域设置
localeconv
setlocale_wsetlocale
字符串到数值函数
strtod_strtod_lwcstod_wcstod_l
strtoimax_strtoimax_lwcstoimax_wcstoimax_l
strtolwcstol_strtol_l_wcstol_l
strtoul_strtoul_lwcstoul_wcstoul_l
strtoll_strtoll_lwcstoll_wcstoll_l
atof_atof_l_wtof_wtof_l