1

So basically I got string array, lets say a[i][b];

so the code looks something like this -

for(int i = 0; i < 3; i++) { for(int n = 0; b < 3; b++) { if(a[i][b] == "s") { cout << a[i][b] << endl; } } } 

the array exists, and I can check it if I just show on console the a[i][b] without if statement, but with if statement it gives me this error -

error: ISO C++ forbids comparison between pointer and integer

Is there any way to fix that?

3
  • don't you think it's important to know what a is? :/ Commented Feb 21, 2012 at 14:12
  • where is n coming into this? can you give us all of the code? Commented Feb 21, 2012 at 14:12
  • Of what type is a? If it is a char**, you might want to check against a single character in your if condition, e.g. if(a[i][b]=='s') Commented Feb 21, 2012 at 14:12

3 Answers 3

5

"s" is a string literal, i.e. a character array, so decays to a pointer. To just compare to a character, use single quotes:

if (a[i][b]=='s') 
Sign up to request clarification or add additional context in comments.

1 Comment

That worked, lol thanks! Will accepted as soon as I will be able to!
3

"s" is a C string literal, if you want to compare with a character use 's'.

Comments

1

put s in single quotes like this 's'
"s" is a text and in C++ there is no String class (native). So "s" is actually a pointer to character sequence and a[i][b] is just a single character.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.