Skip to content
Related Articles

Related Articles

wcslen() function in C++ with Examples

View Discussion
Improve Article
Save Article
Like Article
  • Last Updated : 03 Oct, 2018

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:-




// 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;
}

Output:

The length of 'geeks' is =5

Example 2:-




// 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;
}

Output:

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

=


My Personal Notes arrow_drop_up
Recommended Articles
Page :

Start Your Coding Journey Now!