使用Unicode C ++的飞机符号

时间:2014-10-18 10:47:03

标签: c++ unicode iostream

我试图在我的CodeBlocks中使用Unicode打印飞机符号。我发现飞机的代码是\u2708。所以我尝试了以下代码:

   #include <iostream>

using namespace std;

int main() {
    wchar_t a = '\u2708';
    cout << a;
return 0;
}

当我用char

替换wchar_t时输出​​40072
char a = '\u2708';

我得到这个符号:ł

我真的被困了,谢谢你的帮助。

1 个答案:

答案 0 :(得分:1)

如果您在Linux并且不使用从unicode到控制台的代码转换,请尝试以下操作:

std::locale::global(std::locale(""));
wchar_t plane = L'\u2708';
std::wcout << plane << std::endl;

在Windows中有点复杂,你需要在默认控制台和正确的代码页上使用兼容的unicode字体。