need help cant evaluate a string???

Brett.h's Avatar, Join Date: Dec 2009
Light Poster
I am writing a program that will evalute a string and check for spaces, when I try to compile it I get this error message:

Error 1 error C2446: '==' : no conversion from 'const char *' to 'int' c:\documents and settings\brett\my documents\visual studio 2008\projects\project1\ai learn algorithm\ai learn algorithm\test.cpp 12

what is wrong, and how can I fix it

all help is appreciated,

Brett


getline(cin, teststr);
int counter = 0;
cout << teststr[counter];
if (teststr[counter] == " "){
cout << "test complete";
}
Gene Poole's Avatar, Join Date: Nov 2009
Contributor
Use single quotes for a single character. Double quotes designate an array of characters that decays to a pointer to type char when used as above. Try this:

Code:
  if (teststr[counter] == ' '){
murugaperumal's Avatar, Join Date: Feb 2010
Go4Expert Member
Dear Friend,

To compare the two string ,instead of "==" operator use the compare function.

Sample code
Code:
string str1 ("green apple");
if (str1.compare(6,5,"apple") == 0)
cout << "still, " << str1 << " is an apple\n";