wcslen() function in C++ with Examples
Last Updated :
26 Jun, 2023
Improve
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:-
// 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;
}
18
1
// c++ program to demonstrate
2
// example of wcslen() function.
3
4
5
using namespace std;
6
7
int main()
8
{
9
10
// Get the string to be used
11
wchar_t str[] = L"geeks";
12
13
// Get the length of the string using wcslen()
14
wcout << L"The length of '" << str
15
<< L"' is =" << wcslen(str) << endl;
16
17
return 0;
18
}
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;
}
18
1
// c++ program to demonstrate
2
// example of wcslen() function.
3
4
5
using namespace std;
6
7
int main()
8
{
9
10
// Get the string to be used
11
wchar_t str[] = L"A computer science portal for geeks";
12
13
// Get the length of the string using wcslen()
14
wcout << L"The length of '" << str
15
<< L"' is =" << wcslen(str) << endl;
16
17
return 0;
18
}
Output:
The length of 'A computer science portal for geeks' is =35