共用方式為


_strtoui64、_wcstoui64、_strtoui64_l、_wcstoui64_l

將字串轉換成不帶正負號的 __int64 值。

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

參數

  • nptr
    要轉換的以 Null 結束字串。

  • endptr
    要停止掃描字元的指標。

  • base
    使用的數字底數。

  • locale
    要使用的地區設定。

傳回值

_strtoui64 傳回字串 nptr 所表示的值,但是在造成溢位時例外,在該情況下會傳回 _UI64_MAX。如果沒有轉換動作可以執行,strtoui64 會傳回 0。

_UI64_MAX 定義於 LIMITS.H.。

如果 nptr 為 NULL,或 base 為非零值且小於 2 或大於 36,則 errno 會設定為 EINVAL。

如需有關這些回傳碼和其他回傳碼的詳細資訊,請參閱 _doserrno、errno、_sys_errlist 和 _sys_nerr

備註

_strtoui64 函式會將 nptr 轉換成 unsigned__int64。 _wcstoui64 是 _strtoui64 的寬字元版本。它的 nptr 參數是寬字元字串。 否則,這三個函式的行為相同。

兩個函式都會在第一個無法辨識為數字部分的字元之處停止讀取字串 nptr。 這可能是終止的 null 字元,或者它可能是大於或等於 base 的第一個數字字元。

一般文字常式對應

TCHAR.H 常式

未定義 _UNICODE & _MBCS

已定義 _MBCS

已定義 _UNICODE

_tcstoui64

_strtoui64

_strtoui64

_wstrtoui64

_tcstoui64_l

_strtoui64_l

_strtoui64_l

_wstrtoui64_l

目前地區設定的 LC_NUMERIC 分類設定決定如何辨認目前 nptr 中的基數字元。如需更多的資訊,請參閱設定地區設定。 沒有 _l 後置字元的函式會使用目前的地區設定;_strtoui64_l 和 _wcstoui64_l 與沒有 _l 後置字元的對應函式相同,除非它們使用傳入的地區設定。 如需詳細資訊,請參閱地區設定

如果 endptr 不是 NULL,停止掃描的字元的指標會儲存在 endptr 所指向的位置。 如果轉換無法執行 (未找到有效的數字或指定了無效基底), nptr 的值會儲存在 endptr 所指向的位置。

_strtoui64 預期 nptr 指向下列格式的字串:

[whitespace] [{+ | –}] [0 [{ x | X }]] [digits]

whitespace 可能由會被忽略的空格和定位字元組成; digits 是一個或多個十進位數字。 第一個不符合這個格式的字元會停止掃描。 如果 base 介於 2 和 36 之間,則會使用它當做數字的底數。 如果 base 為 0,則會使用 nptr 指向之字串的初始字元來判斷基底。 如果第一個字元是 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 );
}
  

請參閱

參考

資料轉換

地區設定

localeconv

setlocale、_wsetlocale

字串轉換為數值函式

strtod、_strtod_l、wcstod、_wcstod_l

strtoul、_strtoul_l、wcstoul、_wcstoul_l

atof、_atof_l、_wtof、_wtof_l