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 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!

4

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'

1

A single char is defined with '', so:

if (chAuswahl == 'j')
{
}
0
Chloe Bennett

Chloe Bennett

Culture, Media & Entertainment Columnist

Chloe Bennett explores the intersection of pop culture, streaming entertainment, digital trends, and contemporary lifestyle. Her weekly commentary reaches thousands of culture enthusiasts.

Share this article
Twitter Facebook Pinterest