wcstoul, wcstoull
來自 cppreference.com
在標頭檔案 <wchar.h> 中定義 |
||
unsigned long wcstoul( const wchar_t* str, wchar_t** str_end, int base ); |
(自 C95 起) (直到 C99) |
|
unsigned long wcstoul( const wchar_t * restrict str, wchar_t ** restrict str_end, int base ); |
(C99 起) | |
unsigned long long wcstoull( const wchar_t * restrict str, wchar_t ** restrict str_end, int base ); |
(C99 起) | |
解析指向 `str` 的寬字串中的無符號整數值。
丟棄所有空白字元(透過呼叫 iswspace 識別),直到找到第一個非空白字元,然後儘可能多地獲取字元以形成有效的 *n進位制*(n 為 `base`)無符號整數表示,並將其轉換為整數值。有效的無符號整數值由以下部分組成:
- (可選) 加號或減號
- (可選) 字首(`0`)表示八進位制基數(僅當 `base` 為 8 或 0 時適用)
- (可選) 字首(`0x` 或 `0X`)表示十六進位制基數(僅當 `base` 為 16 或 0 時適用)
- 一系列數字
`base` 的有效值集合是 `{0, 2, 3, ..., 36}`。2 進位制整數的有效數字集合是 `{0, 1}`,3 進位制整數的有效數字集合是 `{0, 1, 2}`,依此類推。對於大於 10 的進位制,有效數字包括字母字元,從 11 進位制的 `Aa` 到 36 進位制的 `Zz`。字元的大小寫被忽略。
當前安裝的 C 區域設定可能會接受其他數字格式。
如果 `base` 的值為 0,則自動檢測數字基數:如果字首是 `0`,則基數是八進位制;如果字首是 `0x` 或 `0X`,則基數是十六進位制;否則基數是十進位制。
如果減號是輸入序列的一部分,則從數字序列計算出的數值將被取反,如同結果型別中的一元減號,這將應用無符號整數環繞規則。
這些函式將 `str_end` 指向的指標設定為指向最後一個被解釋字元之後的寬字元。如果 `str_end` 是空指標,則忽略它。
目錄 |
[編輯] 引數
str | - | 指向要解釋的以 null 結尾的寬字串的指標 |
str_end | - | 指向寬字元的指標的指標。 |
base | - | 被解釋整數值的*基數* |
[編輯] 返回值
成功時,返回與 `str` 內容對應的整數值。如果轉換後的值超出相應返回型別的範圍,則發生範圍錯誤並返回 ULONG_MAX 或 ULLONG_MAX。如果沒有可執行的轉換,則返回 0。
[編輯] 示例
執行此程式碼
#include <stdio.h> #include <errno.h> #include <wchar.h> int main(void) { const wchar_t *p = L"10 200000000000000000000000000000 30 40"; printf("Parsing L'%ls':\n", p); wchar_t *end; for (unsigned long i = wcstoul(p, &end, 10); p != end; i = wcstoul(p, &end, 10)) { printf("'%.*ls' -> ", (int)(end-p), p); p = end; if (errno == ERANGE){ printf("range error, got "); errno = 0; } printf("%lu\n", i); } }
輸出
Parsing '10 200000000000000000000000000000 30 40': '10' -> 10 ' 200000000000000000000000000000' -> range error, got 18446744073709551615 ' 30' -> 30 ' 40' -> 40