#include
#include
#include
int main(void) {
_setmode(_fileno(stdout), _O_U16TEXT);
wprintf(L\"\\x043a\\x043e\\x0448
Don't even bother with it.
Your user needs to set the font of his console to a unicode one (Lucida Console for example), or else it won't display anything. If you're targeting East Asia, where the default font is unicode aware, it'll display fine, but in Europe, you have to change the font manually.
User's won't change their console font because you write it in the readme. They won't even read the readme, they'll just see that it displays garbage, and they will think the program doesn't work.
Also, it's a farly new function VS 2005, so you need to link the VS 2005 redistributeable, msvcr50.dll, or newer (mingw link to msvcrt.dll by default). If you don't do this, the text, won't be displayed at all.
And I think a simple pipe will kill your new and shiny unicode text. Let's say your exe named a.exe. I'm pretty sure, that a.exe | more
will NOT display unicode text.
Well, there's a simple workaround: just use values of these constants instead of their names. For example, _O_U16TEXT
is 0x00020000
and _O_U8TEXT
is 0x00040000
.
I've just confirmed that it works with _setmode
using g++ 4.8.1 on Windows 10:
#include <iostream>
#include <fcntl.h>
#include <io.h>
#include <stdio.h>
int main() {
_setmode(_fileno(stdout), 0x00020000); // _O_U16TEXT
std::wcout << L"Русский текст\n";
}