rsk*_*k82 5 c++ unicode console mingw
#include <fcntl.h>
#include <io.h>
#include <stdio.h>
int main(void) {
_setmode(_fileno(stdout), _O_U16TEXT);
wprintf(L"\x043a\x043e\x0448\x043a\x0430 \x65e5\x672c\x56fd\n");
return 0;
}
Run Code Online (Sandbox Code Playgroud)
在编译时返回错误: _O_U16TEXT was not declared in this scope
这是此编译器的制胜法宝吗?
嗯,有一个简单的解决方法:只需使用这些常量的值而不是它们的名称。例如,_O_U16TEXT
是0x00020000
和_O_U8TEXT
是0x00040000
。
我刚刚确认它可以_setmode
在 Windows 10 上使用 g++ 4.8.1:
#include <iostream>\n#include <fcntl.h>\n#include <io.h>\n#include <stdio.h>\n\nint main() {\n _setmode(_fileno(stdout), 0x00020000); // _O_U16TEXT\n std::wcout << L"\xd0\xa0\xd1\x83\xd1\x81\xd1\x81\xd0\xba\xd0\xb8\xd0\xb9 \xd1\x82\xd0\xb5\xd0\xba\xd1\x81\xd1\x82\\n";\n}\n
Run Code Online (Sandbox Code Playgroud)\n