I was trying to properly handle unicode input/output in winconsole (Polish Windows 10) using std::wcin
, std::wcout
, std::wstring
, etc. I am using Visual Studio 2015 and Character Set in Property Pages is set to Unicode. After some search and couple of tries I managed to get it work with:
_setmode(_fileno(stdout), _O_U16TEXT);
_setmode(_fileno(stdin), _O_U16TEXT);
std::locale::global(std::locale(""));
The problem is I do not quite understand why it works and why I have to use both _setmode
and std::locale
. When I remove _setmode
s output is fine, but non-ascii chars on input aren't handled properly. Commenting std::locale
line makes the program stop working on the very first appearance of non-ascii char on output.
Does someone use the same thing? Could you explain briefly what those functions do? I want to undestand what exactly I am doing.