C++ wchar_t Keyword
Example
Store two wide characters and print their number values:
wchar_t letter1 = L'A';
wchar_t letter2 = L'\u03A9'; // The Greek letter Omega
cout << static_cast<int>(letter1) << "\n";
cout << static_cast<int>(letter2);
Definition and Usage
The wchar_t keyword is a data type that can store a wide character. A wide character can be larger than a char, so it can store letters and symbols from many languages.
Write an L in front of a wide character, like L'A'. In the example above, \u03A9 is the Unicode number of the Greek letter Omega. Its value is 937, which is too large for a char.
The size of wchar_t depends on the system: 2 bytes on Windows, and 4 bytes on most other systems. To print wide characters as text, use wcout instead of cout, but do not use both in the same program.
Related Pages
The char keyword is a data type that stores a single character.
Read more about characters in our C++ Character Data Types Tutorial.