_strtoui64, _wcstoui64, _strtoui64_l, _wcstoui64_l

将字符串转换为 unsigned __int64 值。

语法

unsigned __int64 _strtoui64(
   const char *strSource,
   char **endptr,
   int base
);
unsigned __int64 _wcstoui64(
   const wchar_t *strSource,
   wchar_t **endptr,
   int base
);
unsigned __int64 _strtoui64_l(
   const char *strSource,
   char **endptr,
   int base,
   _locale_t locale
);
unsigned __int64 _wcstoui64_l(
   const wchar_t *strSource,
   wchar_t **endptr,
   int base,
   _locale_t locale
);

参数

strSource
要转换的 null 终止的字符串。

endptr
指向停止扫描的字符的指针。

base
要使用的基数。

locale
要使用的区域设置。

返回值

_strtoui64 返回字符串 strSource 中表示的值,只有当表示形式会导致溢出时才返回 _UI64_MAX。 如果无法执行任何转换,则 _strtoui64 返回 0。

_UI64_MAXLIMITS.H 中定义。

如果 strSourceNULLbase 为非零值,且小于 2 或大于 36,则 errno 设置为 EINVAL

有关返回代码的详细信息,请参阅 errno_doserrno_sys_errlist_sys_nerr

注解

_strtoui64 函数将 strSource 转换为 unsigned __int64_wcstoui64_strtoui64 的宽字符版本;它的 strSource 参数是宽字符字符串。 否则,这些函数具有相同行为。

这两个函数在它们无法识别为数字一部分的首个字符处停止读取字符串 strSource。 这可能是终止 null 字符,也可能是大于或等于 base 的第一个数字字符。

默认情况下,此函数的全局状态范围限定为应用程序。 若要更改此状态,请参阅 CRT 中的全局状态

一般文本例程映射

TCHAR.H 例程 _UNICODE_MBCS 未定义 _MBCS 已定义 _UNICODE 已定义
_tcstoui64 _strtoui64 _strtoui64 _wcstoui64
_tcstoui64_l _strtoui64_l _strtoui64_l _wcstoui64_l

当前区域设置的 LC_NUMERIC 类别设置确定 strSource 中的基数字符的识别;有关详细信息,请参阅 setlocale。 不带 _l 后缀的函数的版本使用当前区域设置;_strtoui64_l_wcstoui64_l 与不带 _l 后缀的相应的函数相同,只不过它们使用传入的区域设置。 有关详细信息,请参阅 Locale

如果 endptr 不为 NULL,则在 endptr 所指向的位置存储指向停止扫描的字符的指针。 如果无法执行任何转换(未找到任何有效的数字或指定了无效的基数),则将 strSource 的值存储在由 endptr 指向的位置。

_strtoui64 需要 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”字符将停止扫描。

要求

函数 必需的标头
_strtoui64 <stdlib.h>
_wcstoui64 <stdlib.h><wchar.h>
_strtoui64_l <stdlib.h>
_wcstoui64_l <stdlib.h><wchar.h>

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

示例

// crt_strtoui64.c
#include <stdio.h>

unsigned __int64 atoui64(const char *szUnsignedInt) {
   return _strtoui64(szUnsignedInt, NULL, 10);
}

int main() {
   unsigned __int64 u = atoui64("18446744073709551615");
   printf( "u = %I64u\n", u );
}
u = 18446744073709551615

另请参阅

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