string

Hi . what is my fault . the compiler return ISO C++ forbids comparison between pointer and integer|
int main()
{
string word;
cout <<"\n enter word\n: ";
getline(cin,word);
for(int i = 0 ; i < word.size(); i++)
{
if(word[i] == " ")
cout <<" find space";
}
return 0;
}

replace
if(word[i] == " ")

with
if(word[i] == ' ')

" " is a string constant (even though its 1 character long, excluding the null terminator)
' ' is a character
Last edited on
thank you . but i don't understand why put this character ' '
Single quotes are for character literals. Double quotes are for string literals (the null character is appended by default). Since word is a std::string, word[i] (if i is in range) is a character, so you must compare it to another character, not to a std::string.
Thank filipe
Topic archived. No new replies allowed.