函式
<cwchar>

wcstoul

unsigned long int wcstoul (const wchar_t* str, wchar_t** endptr, int base);
將寬字串轉換為無符號長整數
解析 C 寬字串str,根據指定的base將其內容解釋為整型數字,並返回unsigned long intlong int

這是 strtoul<cstdlib>)的寬字元等價函式,其解析str的方式與 strtoul 相同。

引數

str
包含整型數字表示的 C 寬字串。
endptr
對一個wchar_t*型別物件的引用,函式會將其值設定為 str 中數值部分之後的下一個字元。
該引數也可以是一個空指標,此時它將不被使用。

返回值

成功時,該函式將其轉換後的整型數字作為unsigned long intlong int
如果無法執行有效的轉換,則返回零值。
如果讀取的值超出了可表示範圍unsigned long intlong intULONG_MAXLONG_MINERANGE.

示例

1
2
3
4
5
6
7
8
9
10
11
12
13
14
/* wcstoul example */
#include <stdio.h>
#include <wchar.h>

int main ()
{
  wchar_t wsInput [256];
  unsigned long ul;
  wprintf (L"Enter an unsigned number: ");
  fgetws (wsInput,256,stdin);
  ul = wcstoul (wsInput,NULL,0);
  wprintf (L"Value entered: %lu. Its double: %lu\n",ul,ul*2);
  return 0;
}

可能的輸出
Enter an unsigned number: 25
Value entered: 25. Its double: 50


另見