International UTF-32 strings output to console in Linux
-
28-03-2021 - |
質問
#include <stdio.h>
#include <iostream>
#include <locale>
int main()
{
const wchar_t *str = L"\u041F\u043E\u0440\u044F\u0434\u043E\u043A";
std::locale::global(std::locale(""));
std::wcout << str << std::endl;
}
Here's a piece of code that outputs a russian phrase in UTF-32 wchar_t string as:
- The correct one: Порядок when run from UTF-8 gnome terminal in Ubuntu 11.10
- РџРѕСЂСЏРґРѕРє in Eclipse in the test run as above
- 45=B8D8:0B>@ in Eclipse in a real program (where I don't even know who does what and where, but I suppose someone does mess with locales)
- ??????? if I don't call locale
- str is shown as Details:0x400960 L"\320\237\320\276\321\200\321\217\320\264\320\276\320\272" in Eclipse Watch window
- is shown as ASCII only byte chars in Eclipse memory window (and there's no way to specify that this is UTF-32 string)
I believe this is a misconfiguration in either eclipse console or the program, because, for example, other people that just run my code in Eclipse they do see the correct output.
Could someone shed a light on this confusion? What is the correct way to setup all the pieces (OS, gcc, terminal, Eclipse, sources...) to output international symbols that are stored in UTF-32 wchar_t strings?
And as a side note, why should I still care about all this when we have UTF-32 and that should be enough to know what is inside...
解決
It turned out to be that other code changed locale.
所属していません StackOverflow