Compare Two Char in C++ [Closed]
Why Does It Not Work to Compare Two Char? My Code First Declares a Char, Then the User Gives a Value to It -> "J" or "T". Then the Following Code Looks Like...
Why does it not work to compare two char?
My code first declares a char, then the user gives a value to it -> "j" or "t".
Then the following code looks like this:
if (chAuswahl == "j")
{
}
My problem is, that == is red underlined. This is the error code:
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 *").
Thank you all for help!
2 Answers
To expand a little on the comment above, 'c' and "c" have different meanings in C++. The former is a character literal, while the latter is a string (char*) literal.
For completeness, you'll want to replace "j" with 'j'
A single char is defined with '', so:
if (chAuswahl == 'j')
{
}