我试图弄明白为什么一个8位的字符串文字可以包含多字节字符,而一个字符向量不能?
Let me better explain:
We can do this:
char chars[] = "????????????????必西♠♬♭♮♯"; // the compiler adds '\0'
// sizeof(chars) is 38 bytes
但我们不能这样做:
char chars[] = { '????', '????', '????', '????', '必', '西', '♠', '♬', '♭', '♮', '♯', '\0'};
// error: narrowing conversion of ‘-257972808’ from ‘int’ to ‘char’ [-Wnarrowing]
我们必须这样做:
wchar_t chars[] = { '????', '????', '????', '????', '必', '西', '♠', '♬', '♭', '♮', '♯', '\0'};
// sizeof(chars) is 48 bytes
// no errors
字符串文字符号不是字符向量的简单快捷方式吗?