Tutorialspoint.dev

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

=



This article is attributed to GeeksforGeeks.org

tags:

C++ CPP

leave a comment

code

0 Comments

load comments

Subscribe to Our Newsletter