wcslen() function in C++ with Examples

The wcslen() function is defined in cwchar.h header file. The function wcslen() function returns the length of the given wide string.

Syntax:

size_t wcslen(const wchar_t* str);

Parameter: This method takes a single parameter str which represents the pointer to the wide string whose length is to be calculated.



Return Value: This function returns the length of wide string.

Below programs illustrate the above function:-

Example 1:-

filter_none

edit
close

play_arrow

link
brightness_4
code

// c++ program to demonstrate
// example of wcslen() function.
  
#include <bits/stdc++.h>
using namespace std;
  
int main()
{
  
    // Get the string to be used
    wchar_t str[] = L"geeks";
  
    // Get the length of the string using wcslen()
    wcout << L"The length of '" << str
          << L"' is =" << wcslen(str) << endl;
  
    return 0;
}

chevron_right


Output:

The length of 'geeks' is =5

Example 2:-

filter_none

edit
close

play_arrow

link
brightness_4
code

// c++ program to demonstrate
// example of wcslen() function.
  
#include <bits/stdc++.h>
using namespace std;
  
int main()
{
  
    // Get the string to be used
    wchar_t str[] = L"A computer science portal for geeks";
  
    // Get the length of the string using wcslen()
    wcout << L"The length of '" << str
          << L"' is =" << wcslen(str) << endl;
  
    return 0;
}

chevron_right


Output:

The length of 'A computer science portal for geeks' is =35

=



My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.




Article Tags :
Practice Tags :


Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.