Why do I get an error when I want to compare a char variable with a character?

0

Hi, I did a function in C ++ where you must enter characters that are inserted in a set passed by parameter until "*" is entered. But I get an error when comparing the while (comparison between pointer and integer ( int and const char * ), I would like to know what is wrong.

set <char> ingresar_caracter(set <char> conjunto){
char caracter;
cout << "Ingrese un caracter (* para terminar): ";
cin >> caracter;
cout << endl;
while(caracter != "*") comparison between pointer and integer ('int' and 'const char *')
{
    conjunto.insert(caracter);
    cout << "Ingrese otro caracter (* para terminar): ";
    cin >> caracter;
    cout << endl;
}
return conjunto;
}

I'm using the QCreator

    
asked by novato 23.10.2018 в 21:09
source

1 answer

3

The error is self-explanatory. You are comparing a character with a text string.

Replace

while(caracter != "*")

By

while(caracter != '*')

Remember that double quotes return a type char * while single quotes return a type char

    
answered by 23.10.2018 в 21:42