I am doing a series of searches in a string, and somewhere along the line one of the strings will be missed, and my set of searches should fail.
I had expected that once the position reached std::string::npos it would stay there, but it does not. Passing std::string::npos to std::string.find seems to start the search at the beginning again
std::string str("frederick");
std::string::size_type pos = str.find("der",std::string::npos);
TS_ASSERT_EQUALS(pos, std::string::npos); // FAIL, 3 is returned
Why is it not being taken to indicate the end of the string?
Update: The intention is search for a series of strings in order, and check the result at the end
pos = str.find(string1, pos)
pos = str.find(string2, pos)
pos = str.find(string3, pos)
if (pos != std:string::npos)
{ // All strings found