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

devxblackblue

About Our Editorial Process

At DevX, we’re dedicated to tech entrepreneurship. Our team closely follows industry shifts, new products, AI breakthroughs, technology trends, and funding announcements. Articles undergo thorough editing to ensure accuracy and clarity, reflecting DevX’s style and supporting entrepreneurs in the tech sphere.

See our full editorial policy.

About Our Journalist