我在源代码中使用了带有音标的字符,并尝试用Unicode等效字符替换它们。如果我使用实际的非ASCII字符,程序编译并正常工作,但我担心这可能会影响可移植性。当我尝试使用Unicode等效字符时,我会得到“警告:情况标签值超过类型的最大值”或“警告:字符常量对其类型太长”,并且在运行程序时该情况永远不匹配。
for(int i = 0; i < ent->d_namlen; i++)
{
switch(ent->d_name[i])
{
case 'á' : //0x00E1
...
}
}
参数ent
是一个从调用函数传递过来的 struct dirent *
。
在 case 'á' :
的位置,我尝试了 case '0x00E1' :
, case L 'u00E1 :
, case \U000000E9 :
和 case '\u00E1' :
。但是如果没有使用单引号,则无法编译(例如,会说在此范围内未声明 \u00E1)。
dirent.d_name
是char[]
。 - obatakuprintf(“%d”,d_name [whatever])
或std :: cout <<(int)d_name [whatever]
。 - Pete Becker