C++ Standard Library C++ STL Library

C++ <cwchar> - wcslen() Function



The C++ <cwchar> wcslen() function returns the length of a wide string, which is, the number of characters in the wide string whose first element is pointed to by str (without including the terminating null character).

The behavior is undefined if there is no null character in the wide character array pointed to by str.

Syntax

size_t wcslen ( const wchar_t * str );

Parameters

str Specify pointer to the wide character array.

Return Value

Returns the length of a wide string.

Example:

The example below shows the usage of wcslen() function.

#include <iostream>
#include <cwchar>
using namespace std;
 
int main (){
  wchar_t str1[256] = L"Hello World!";
  wchar_t str2[256] = L"Programming is easy.";

  cout<<"str1 contains: "<<wcslen(str1)<<" characters.\n";
  cout<<"str2 contains: "<<wcslen(str2)<<" characters.\n";   
  return 0;
}

The output of the above code will be:

str1 contains: 12 characters.
str2 contains: 20 characters.

❮ C++ <cwchar> Library