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;


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');

Share the Post:
Share on facebook
Share on twitter
Share on linkedin

Overview

Recent Articles: