【发布时间】:2014-02-15 13:25:31
【问题描述】:
我刚刚意识到(感谢我的大学课程)我认为我知道的关于 unicode 的许多事情都是错误的。因此,我开始阅读和修正我的知识,通过在 MSVC2012 中玩一个简单的“Hello world”C++ 程序,立即产生了以下疑问:
#include <iostream>
#include <string.h>
using namespace std;
int main(void) {
char arr1[] = "I am a nice boy"; // Is this stored as UTF-8 (multi-byte) or ASCII?
char arr[] = "I'm a nice èboi"; // All characters should be ASCII except the 'è' one, which encoding is used for this?
cout << strlen(arr); // Returns 15 as ASCII, why?
// If I choose "multi-byte character set" in my VS project configuration instead of "unicode", what does this mean and what
// will this affect?
char arr2[] = "I'm a niße boy"; // And what encoding is it used here?
cout << strlen(arr2); // Returns 1514, what does this mean?
// If UTF-32 usually use 4 bytes to encode a character (even if they're not needed), how can a unicode code point like U+FFFF
// (FFFF hexadecimal is 65535 in decimal) represent any possible unicode character if the maximum is FFFF ? (http://inamidst.com/stuff/unidata/)
return 0;
}
上面是用“多字节字符集”编译的,但由于多字节是一种 unicode 编码,我猜(?)即使这也不清楚。
有人可以为上述问题提供清晰的解释吗?
【问题讨论】:
-
这不是关于 Unicode,而是关于 VS2012。如果您根本不了解您是否使用 Unicode,那么根本就没有 Unicode 问题。
-
然后编辑问题并添加标签,如果您认为是这样。
-
先生。克宁,我觉得你的语气不礼貌。您可以提出一个可以回答的问题。如果您知道您的源文件是 UTF-8 还是某些非 unicode 代码页,请编辑您的问题。如果您不这样做,请继续编辑您的问题,或者更好的是,找出然后编辑您的问题。
-
我一开始就觉得你的语气不礼貌。请让我们都安顿下来。对不起,如果我写错了,那是因为我很困惑,而不是因为我试图表达自己的观点。我用 vs2012 标签和我设置的属性编辑了问题
-
我认为你的代码会为第 8 行产生错误 " cout
标签: c++ visual-studio-2012 unicode character-encoding multibyte