I am writing some output to the console. I set the console output codepage according to this page, and use _setmode
to utf8 according to this answer.
This is my code:
SetConsoleOutputCP(CP_UTF8);
_setmode(_fileno(stdout), _O_U8TEXT);
wstring str = L"Testing unicode -- English -- Ελληνικά -- 中文 -- Español -- けものフレンズ -- abc1234.";
wcout << str << endl;
This piece of code print correctly on my Windows 10 (Traditional Chinese) and a Windows 7(Japanese) machine, but still cannot show unicode text in a Windows 10 (English) machine:
I checked the console codepage which is already 65001(UTF-8), and I tried different fonts, but no changes. How can I display correctly?
UPDATE:
I tried explicitly transforming the string into unicode like:
wstring example = L"Testing unicode -- English -- \u0395\u03bb\u03bb\u03b7\u03bd\u03b9\u03ba\u03ac \u002d\u002d \u4e2d\u6587 \u002d\u002d \u0045\u0073\u0070\u0061\u00f1\u006f\u006c \u002d\u002d \u3051\u3082\u306e\u30d5\u30ec\u30f3\u30ba -- abc1234.";
wcout << example << endl;
And then it will print out correctly (only if I choose "MS Gothic" or "MingLiU" font).
I wonder why the first string is not correct in English environment?