How do I check if a C++ std::string starts with a certain string, and convert a substring to an int?

Use rfind overload that takes the search position pos parameter, and pass zero for it: Who needs anything else? Pure STL! Many have misread this to mean “search backwards through the whole string looking for the prefix”. That would give the wrong result (e.g. string(“tititito”).rfind(“titi”) returns 2 so when compared against == 0 would return false) and it would be inefficient (looking through … Read more