This is my program:
#include <iostream>
#include <string>
#include <locale>
#include <clocale>
#include <codecvt>
#include <io.h>
#include <fcntl.h>
int main()
{
fflush(stdout);
_setmode(_fileno(stdout), _O_U16TEXT);
std::ios_base::sync_with_stdio(false);
std::setlocale(LC_ALL, "el_GR.utf8");
std::locale loc{ "el_GR.utf8" };
std::locale::global(loc); // apparently this does not set the global locale
//std::wcout.imbue(loc);
//std::wcin.imbue(loc);
std::wstring yes;
std::wcout << L"It's all good γεια ναί" << L'\n';
std::wcin >> yes;
std::wcout << yes << L'\n';
return 0;
}
Lets say I want to support greek encodings (for both input and output). This program works perfectly on Linux for various output and input languages if I set the appropriate encoding and of course remove the fflush(stdout)
and _setmode()
.
So on Windows this program will output greek (and english) correctly when I use std::locale::global(loc)
, but It will not take greek input that I type from the keyboard. The std::wcout << yes
outputs gibberish or question marks if I type greek. Apparently ::global
isn't really global on Windows?
So I tried the .imbue()
method on wcout
and wcin
(which also works on Linux) that you see commented out here. When I use any of these two statements and run the program it will (compile properly) present me with a prompt and when I press w/e and then press 'enter' it simply exits with no errors or whatnot.
I have tried a few Windows specific commands but then I got confused too. What should I try and when on Windows is not clear to me.
So the question is how I can both input and output greek text properly in Windows like in the program above? I use MSVS 2017 latest updates. Thanks in advance.