Reputation: 2935
Using C++ VS 2015.
How do you compare (if) array of string to a constant character without error.
string GBD[9] = { "wKQkq--000"," "," "," "," "," "," "," "," " };
if (GBD[0][0] = "w")
{ cout << "it is w"; }
Error is: C2440 '=': cannot convert from 'const char [2]' to 'char'
I tried "=="
Error is: C2446 '==': no conversion from 'const char *' to 'int'
Sorry a bit rusty. I thought since a string is an array of characters, so I assumed two dim array is equal to a character of a one dimension array of string.
Upvotes: 1
Views: 52
Reputation: 147
check like this:
if (GBD[0][0] == 'w')
{ cout << "it is w"; }
Upvotes: 1
Reputation: 42858
if (GBD[0][0] == 'w')
'w'
is a character, "w"
is a string literal.
Upvotes: 1