c++, cout and UTF-8

后端 未结 4 515
萌比男神i
萌比男神i 2020-12-19 03:44

Hopefully a simple question: cout seems to die when handling strings that end with a multibyte UTF-8 char, am I doing something wrong? This is with GCC (Mingw)

4条回答
  •  甜味超标
    2020-12-19 04:20

    The Windows console does not handle non-local-codepage characters by default.

    You'll need to make sure you have a Unicode-capable font set in the console window, and that the codepage is set to UTF-8 through a call to chcp. This is not a guaranteed success though. Note that `wcout´ changes nothing if the console can't show the fancy characters because its font is botched.

    On all modern Linux distros, the console is set to UTF-8 and this should work out of the box.

提交回复
热议问题