Skip to content
Related Articles
Open in App
Not now

Related Articles

wcslen() function in C++ with Examples

Improve Article
Save Article
  • Last Updated : 20 Feb, 2023
Improve Article
Save Article

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.

Time Complexity: O(1)

Auxiliary Space: O(1)

 Below programs illustrate the above function:- Example 1:- 

cpp




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

cpp




// 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
Related Articles

Start Your Coding Journey Now!