函式
<cwchar>

wcslen

size_t wcslen (const wchar_t* wcs);
獲取寬字串長度
返回 C 寬字串 wcs 的長度。

這是 wcs 和第一個 空寬字元 之間的寬字元數(不包括空寬字元)。

這是 strlen (<cstring>) 的寬字元等價物。

引數

wcs
C 寬字串。

返回值

C 寬字串的長度。

示例

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

int main ()
{
  wchar_t wsInput[256];
  wprintf (L"Enter a sentence: ");
  fgetws ( wsInput, 256, stdin );  /* includes newline characters */
  wprintf (L"You entered %u characters.\n",wcslen(wsInput));
  return 0;
}

輸出

Enter sentence: just testing
You entered 13 characters.


另見