我正在尝试使用Clion在C ++中使用希伯来语字符在mac。
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.
这个for的输出是:
-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个希伯来字符?
答案 0 :(得分:2)
您会看到“א”的UTF8代码。但显然你的终端不支持这个charset或UTF8。 ( - 41,-112)=(0xd7,0x90)
Look here for UTF8 hebrew characters
您需要了解如何配置终端以支持希伯来语字符集和UTF8。
答案 1 :(得分:2)
这里有几个子问题。
<强> A)强>
您需要某种Unicode格式的数据,而不是基于ASCII的单字节字符。你已经拥有了,但如果没有,世界上没有任何编程语言功能会自动为你做这件事。
<强> b)中强>
由于你有UTF8,取决于你正在做什么,std::string
等可以很好地处理数据
例如。
的问题是什么?
varname[number]
...对于这样的事情,你需要更多的编码和/或外部库,如ICU。
<强> c)中强>
如果您想直接打印此类搅拌(或读取用户输入),您的终端需要支持UTF8。这完全取决于所使用的操作系统及其配置,C ++部分在这里无法提供帮助。见例如。 OS X Terminal UTF-8 issues