First add some error checking. Check what wcin.good() returns after input and what wcout.good() returns after typing "You are logged in"? I suspect one of them will return false .
What are your environment variables LANG and LC_* set to?
Then try to fix this by adding this at the top of your main() : wcin.imbue(std::locale("")); wcout.imbue(std::locale("")); wcin.imbue(std::locale("")); wcout.imbue(std::locale(""));
I donβt have my Ubuntu right now, so I'm flying blind here and mostly guessing.
UPDATE
If the above suggestion does not help, try creating a locale like this and imbue() instead of locale.
std::locale loc ( std::locale (), new std::codecvt_byname<wchar_t, char, std::mbstate_t>("")));
Strike>
UPDATE 2
Here is what works for me. The key should also set the locale C. IMHO, this is an error in the implementation of the GNU C ++ standard library. If I am mistaken, setting std::locale::global(""); must also set the locale of the C library.
#include <iostream> #include <locale> #include <clocale> #define DUMP(x) do { std::wcerr << #x ": " << x << "\n"; } while (0) int main(){ using namespace std; std::locale loc (""); std::locale::global (loc); DUMP(std::setlocale(LC_ALL, NULL)); DUMP(std::setlocale(LC_ALL, "")); wcin.imbue (loc); DUMP (wcin.good()); wchar_t aChar = 0; wcin >> aChar; DUMP (wcin.good()); DUMP ((int)aChar); wcout << L"You entered " << aChar << L" .\n"; return 0; }
UPDATE 3
I am confused, now I can not play it again, and setting std::locale::global(loc); seems to be doing the right thing wrt / locale. Besides,
source share