For example:
cout << \"你好\" << endl;
The Windows console supports Unicode, partially. It does not support, for example, right-to-left languages.
Your example with cout
does not output unicode. Use wcout
instead. Or use WriteConsoleW
It depends on the platform and on the encoding of the command prompt.
That said, you might have more luck with
std::wcout << L"你好" << std::endl;
Depends on the operating system and implementation. The currently active C++ standard doesn't even talk about Unicode.
On Windows I believe you can use the wide character versions. Your code would then need to be:
std::wcout << L"ni3 hao3" << std::endl;
However, you might have to specifically enter the Unicode character codes because the codeset you're using to write your C++ source might not be Unicode.
It all depends on the console/shell you are using.
Some shells can be configured to use UTF-8 (I did it once a long time ago) so it can be done but I forget the details.
Before anbody can really be more specific we need to know the shell you are using and under what platform the shell is running (with full details about versions of each).
Since you're talking Windows you're talking console windows.
Windows console windows are Unicode-based, more specifically UCS-2 (the Basic Multilingual Plane, essentially original 16-bit Unicode).
Contrary to what's suggested in other answers you can't really do more wrt. results with std::wcout
than with std::cout
. The standard wide output streams just translate to the program's single byte execution character encoding. Which by default in Windows is the OEM character encoding (which can be configured via an undocumented registry key).
But you can output Unicode via the Windows API's console functions.
Note: it's not a good idea to set console windows to UTF-8. Then the [cmd.exe] command interpreter just silently ignores most commands. At least in Windows XP and earlier.
Me I just set OEM to Windows ANSI Western (via the mentioned undocumented registry key) and it works for most purposes, but not Chinese of course. It's codepage 1252. Alternatively you can do that manually via command chcp 1252
in each command interpreter instance, and also other ways.
Cheers & hth.,