共用方式為


strtoul、 _strtoul_l、 wcstoul、 _wcstoul_l

將字串轉換成不帶正負號的長整數值。

unsigned long strtoul(
   const char *nptr,
   char **endptr,
   int base 
);
unsigned long _strtoul_l(
   const char *nptr,
   char **endptr,
   int base,
   _locale_t locale
);
unsigned long wcstoul(
   const wchar_t *nptr,
   wchar_t **endptr,
   int base 
);
unsigned long _wcstoul_l(
   const wchar_t *nptr,
   wchar_t **endptr,
   int base,
   _locale_t locale
);

參數

  • nptr
    要轉換的 null 結尾字串。

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

  • base
    若要使用的數目已經基底。

  • locale
    若要使用的地區設定。

傳回值

strtoul如果有的話,則傳回已轉換的值,或ULONG_MAX發生溢位。 strtoul如果可以不執行任何轉換,則傳回 0。 wcstoul傳回值為 analogously strtoul。 對於這兩個函式中, errno設定為 [ ERANGE發生溢位或反向溢位。

請參閱 _doserrno、 errno、 _sys_errlist,以及 _sys_nerr 如需有關篩選器及其他的詳細資訊,任何傳回碼。

備註

每個函式會將輸入的字串轉換nptr到unsignedlong。 

strtoul停止讀取字串nptr在它無法辨識的數字的第一個字元。 這可能是結束的 null 字元,或可能是第一個數字大於或等於base。 LC_NUMERIC的地區設定的分類設定會決定辨識基數字元的nptr。 如需詳細資訊,請參閱 setlocale。 strtoul與 wcstoul使用目前的地區設定; _strtoul_l與 _wcstoul_l完全相同,不同之處在於它們使用地區設定中傳遞。 如需詳細資訊,請參閱 地區設定

如果endptr不是NULL,要停止掃描的字元指標儲存在所指位置endptr。 如果可以不執行任何轉換 (找不到沒有有效的數字或指定無效的基底) 的值nptr儲存在所指位置endptr。

wcstoul寬字元版本的strtoul。 其nptr引數為寬字元字串。 否則這些函式的行為都相同。

泛用文字常式對應

TCHAR。H 常式

_UNICODE & 未定義的 _MBCS

定義的 _MBCS

定義 _unicode 之後

_tcstoul

strtoul

strtoul

wcstoul

_tcstoul_l

strtoul_l

_strtoul_l

_wcstoul_l

strtoul預期nptr為指向字串的格式如下:

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

A whitespace可能會包含空格及 tab 鍵字元,會被忽略 ; digits有一或多個十進位數字。 不適合這種形式的第一個字元就會停止掃描。 如果base是介於 2 和 36,那麼它會使用的數字基底。 如果base為 0,起始的字元字串所指的nptr用來判斷基底。 如果第一個字元是 0,第二個字元不是 'x' X',字串會解譯為八進位的整數。 否則,它即解譯為十進位的數字。 如果第一個字元是 '0',第二個字元是 'x' X',字串會解譯成十六進位整數。 如果第一個字元是 '1' 到' 9',此字串會解譯為十進位整數。 字母 'a' 到 'z' (或 'A' 到 'Z') 被指派的值 10,透過 35。 字母其指派的值是小於base允許的。 strtoul允許加號 (+) 或減號 (–) 符號前置詞。 前置的負號,表示傳回的值就會失效。

需求

常式

所需的標頭

strtoul

<stdlib.h>

wcstoul

<stdlib.h> 或者 <wchar.h>

_strtoul_l

<stdlib.h>

_wcstoul_l

<stdlib.h> 或者 <wchar.h>

其他的相容性資訊,請參閱相容性在簡介中。

範例

請參閱範例的 strtod

.NET Framework 對等用法

System::Convert::ToUInt64

請參閱

參考

資料轉換

地區設定

localeconv

setlocale _wsetlocale

數字值的函式的字串

strtod、 _strtod_l、 wcstod、 _wcstod_l

strtol、 wcstol、 _strtol_l、 _wcstol_l

atof、 _atof_l、 _wtof、 _wtof_l