为什么不能比较两个char
? 我的代码首先声明一个char
,然后用户给它一个值 - >“j”或“t”。 然后将下面的代码如下所示:比较C++中的两个字符
if (chAuswahl == "j")
{
}
我的问题是,==
是红色下划线。这是错误代码:
Can't convert from const char* to int
'int' is different from const char[2] of performed in terms of the number dereferencings
Operand types are incompatible ("char" and "const char *").
谢谢大家的帮助!
'如果(chAuswahl == 'J')' – syntagma
要在什么@REACHUS说exapand,' “J”'是一个字符串的语法而'j''是单个字符的语法。 –
这个错误令人困惑,因为'char'和'int'是兼容的,所以如果你在那里使用字符或整数,编译器并不在乎。为了您的理智,请在错误消息中读取'int'的'char'。 –