'==' operator error? 12 16 [Error] no match for 'operator==' (operand types are 'std::string {aka std::basic_string<char>}' and 'int')
Im trying to make a yes or no question input but when i use if(response == 'yes') i get the no match for operator error, i am new so forgive if it is a rather stupid question ;)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
//random9
#include <iostream>
#include <string>
usingnamespace std;
int main()
{
string response;
cout << "Do you like me?\n";
cin >> response;
if (response == 'yes') {
cout << "Good.\n";
}
}
You are trying to compare strng and integral number, which causes an error as expected
'yes' — is a multicharacter literal and has a type of int "yes" — is a string literal and has a type of const char*, iplicitly convertible to std::string