wcstombs() function in C++ STL

wcstombs() is a builtin function in C++ STL which converts a wide character string to its equivalent multibyte sequence. It is defined within the cstdlib header file of C++.

Syntax

wcstombs(d, s, n)

Parameters:

Return Value:

Program 1:



filter_none

edit
close

play_arrow

link
brightness_4
code

// Program to illustrate
// wcstombs function in C++
#include <cstdlib>
#include <iostream>
using namespace std;
  
int main()
{
    wchar_t s[] = L"GeeksforGeeks";
    char d[100];
    int n;
  
    n = wcstombs(d, s, 100);
    cout << "Number of wide character converted = "
         << n << endl;
    cout << "Multibyte Character String = "
         << d << endl;
  
    return 0;
}
chevron_right

Output:
Number of wide character converted = 13
Multibyte Character String = GeeksforGeeks

Program 2:

filter_none

edit
close

play_arrow

link
brightness_4
code

// Program to illustrate
// wcstombs function in C++
#include <cstdlib>
#include <iostream>
using namespace std;
  
int main()
{
    wchar_t s[] = L"10@Hello World!";
    char d[100];
    int n;
  
    n = wcstombs(d, s, 100);
    cout << "Number of wide character converted = "
         << n << endl;
    cout << "Multibyte Character String = "
         << d << endl;
  
    return 0;
}
chevron_right

Output:
Number of wide character converted = 15
Multibyte Character String = 10@Hello World!

Don’t stop now and take your learning to the next level. Learn all the important concepts of Data Structures and Algorithms with the help of the most trusted course: DSA Self Paced. Become industry ready at a student-friendly price.





Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.



Improved By : ManasChhabra2

Article Tags :
C++
Practice Tags :