strings: find() function confusion?

Hi,
When using the predefined function find() to search a string for a substring or character, I've noticed that if it can't be found, c++ returns 4294967295. Now, I know a practical solution: an if statement ensuring that the position is less than the length of the word. But I'd like to know why this happens, rather than, say, a fault message?
TIA
seastar12
Last edited on
convert what it returns to an int
(int)mystring.find(...);

youll find its returning -1
Last edited on
The value you should check against is std::string::npos.

1
2
3
4
5
std::string line;
if(line.find("word") != std::string::npos)
{
    // word was found
}


http://www.cplusplus.com/reference/string/string/find/
Last edited on
Topic archived. No new replies allowed.