You have to check against std::string::npos the return value of the find() method.
std::string::size_type pos = string1.find("*");
if(std::string::npos != pos)
{
// found a match at 'pos'
}
else
{
// not found
}
For information on std::string::npos see http://www.cplusplus.com/reference/string/string/npos.html
mitrmkar
Posting Virtuoso
1,809 posts since Nov 2007
Reputation Points: 1,105
Solved Threads: 395
this is because:
Return Value for string.find(...) is:
1) The position of the first occurrence in the string of the searched content.
or
2) If the content is not found, the member value npos is returned.
so your if(...) always evaluates to true.
ninjaneer
Junior Poster in Training
56 posts since Jun 2008
Reputation Points: 10
Solved Threads: 6