国际 UTF-32 字符串输出到 Linux 中的控制台
#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;
}
下面是一段以 UTF-32 wchar_t 字符串形式输出俄语短语的代码:
- 正确的代码: Порядок 当从 Ubuntu 11.10
- РџРѕСЂСЏРйРѕРє 中的 Ubuntu 11.10 中的 UTF-8 gnome 终端运行时,在上面的测试运行中
- 45=B8D8:0B>@ 在 Eclipse 中的真实程序(我什至不知道谁在哪里做什么,但我想有人确实搞乱了语言环境)
- ??????如果我不调用 locale
- 为 Details:0x400960 L"\320\237\320\276\321\200\321\217\320\264\320\276\320\272"
- str 在 Eclipse Watch 窗口中显示 在 Eclipse 内存窗口中仅显示为 ASCII 字节字符(并且无法指定这是 UTF-32 字符串)
我相信这是 Eclipse 控制台或程序中的错误配置,因为,例如,其他人只是在 Eclipse 中运行我的代码,他们会这样做 查看正确的输出。
有人可以阐明这种混乱吗?设置所有部分(操作系统、gcc、终端、Eclipse、源...)以输出存储在 UTF-32 wchar_t 字符串中的国际符号的正确方法是什么?
顺便说一句,当我们有 UTF-32 时,为什么我还应该关心所有这些,并且这应该足以知道里面的内容......
#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...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
事实证明是其他代码改变了语言环境。
It turned out to be that other code changed locale.