【发布时间】:2015-12-03 09:44:47
【问题描述】:
我正在尝试在 C++ 中使用希伯来语字符,在 mac 上使用 Clion。
char notification[140]={"א"}; //this is ALEF the first letter of Hebrew ABC.
for(int i=0; i < strlen(notification); i++) {
cout << (int)notification[i] << endl;
} //Here I want to see what is the ASCII code for this letter.
这个的输出是:
-41
-112
虽然只输入了 1 个字符。
cout << char(-41) << char(-112) << endl; // this one gives me the output of the letter ALEF
cout << char(-41) << char(-111) << endl; //gives the second letter of Hebrew ABC.
我不明白它是如何工作的,为什么有 2 个字符来表示 1 个希伯来字符?
【问题讨论】:
-
这是一个两字节的 Unicode 字符。
-
你需要使用宽字符,即unicode
-
如果你需要实际的 unicode 处理,你需要一个像 ICU 这样的库。
char、wchar、string、wstring以及标准库中的其他任何东西都没有实现 unicode。 -
@BaummitAugen 没有办法使用标准库来处理希伯来字符?
-
@IgorR。您知道如何使用两字节 unicode 字符吗?例如,如果我想做一些 if : if(notification[0]==/*tow-byte char*/) dosomething();