Example:
#include <iostream> using namespace std; int main() { wchar_t en[] = L"Hello"; wchar_t ru[] = L"Привет"; //Russian language cout << ru << endl << en; return 0; }
This code only prints HEX-values like adress. How to print the wchar_t string?
We can see that to make wide character we have to add 'L' before the character literal. But the character value is not displayed in the output using cout. So to use wide char we have to use wcout, and for taking input we have to use wcin. We can make some wide character array, and print them as string.
The wchar_t type is an implementation-defined wide character type. In the Microsoft compiler, it represents a 16-bit wide character used to store Unicode encoded as UTF-16LE, the native character type on Windows operating systems.
Edit: This doesn’t work if you are trying to write text that cannot be represented in your default locale. :-(
Use std::wcout
instead of std::cout
.
wcout << ru << endl << en;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With