How to print UTF-8 strings to std::cout on Windows?

后端 未结 7 1209
南旧
南旧 2020-12-08 07:11

I\'m writing a cross-platform application in C++. All strings are UTF-8-encoded internally. Consider the following simplified code:

#include 
#         


        
相关标签:
7条回答
  • 2020-12-08 08:09

    Some Unicode characters can't be displayed properly in a console window even if you've changed the code page, because your font does not support it. For example, you need to install a font that supports Arabic if you want to show Arabic characters.

    This stackoverflow page should be helpful.

    By the way, the Unicode version of console APIs (such as WriteConsoleW) won't come to the rescue, because they internally call their corresponding Windows code page version APIs (such as WriteConsoleA). Neither will std::wcout help, because it will convert wchar_t string to char string internally.

    It seems that windows console window doesn't support Unicode well, I suggest you use MessageBox instead.

    0 讨论(0)
提交回复
热议问题