Can command prompt display unicode characters?

后端 未结 5 601
不知归路
不知归路 2021-01-20 01:49

For example:

cout << \"你好\" << endl;
5条回答
  •  野的像风
    2021-01-20 02:49

    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.,

提交回复
热议问题