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:-
// 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
=
Want to learn from the best curated videos and practice problems, check out the C++ Foundation Course for Basic to Advanced C++ and C++ STL Course for foundation plus STL. To complete your preparation from learning a language to DS Algo and many more, please refer Complete Interview Preparation Course.


