The mbtwoc() function is defined in <cstdlib> header file.
int mbtowc (wchar_t* pwc, const char* pmb, size_t max);
The mbtowc() function takes three arguments and returns an integer value. This function converts the multibyte character pointed by pmb to a wide character (value of type wchar_t) and is stored at the memory location pointed by pwc.
If pmb is a null pointer, a call to mbtowc() will reset the global conversion state and determines whether shift sequences are used.
If pmb is not a null pointer, mbtowc() returns:
If pmb is a null pointer, resets its internal conversion state to represent the initial shift state and returns:
#include <iostream>
#include <cstdlib>
#include <cstring>
using namespace std;
int main()
{
char pmb[] = "Welcome to Programiz.com";
wchar_t pwc[100];
int len, ret_val;
/* resets internal conversion state */
mbtowc (NULL, NULL, 0);
len = strlen(pmb);
ret_val = mbtowc(pwc, pmb, strlen(pmb));
cout << "Return Value = " << ret_val << endl;
wcout << "Wide character string: " << pwc;
return(0);
}
When you run the program, a possible output will be:
Return Value = 1 Wide character string: W@