Share via


_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_MAX 定義于 中 LIMITS.H

如果 strSourceNULL,或 base 為非零值且小於 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_l, wcstod, _wcstod_l
strtoul, _strtoul_l, wcstoul, _wcstoul_l
atof, _atof_l, _wtof, _wtof_l