devxlogo

Converting char to wchar_t

Converting char to wchar_t

The standard iostream family of classes defines the widen() member function which converts a single char to its wide-character equivalent. widen() has the following prototype:

 char_type widen(char c) const;

size=3>
The char_type typedef represents a system- and locale-dependent codeset of characters, e.g., Unicode. To obtain the wide-char value that corresponds to the ASCII value of lowercase a, do the following:

 whcar_t wa = cin.widen('a');

size=3>

devx-admin

Share the Post: