Search from the end
#include <string> #include <iostream> int main( ) { std::string s = "Search from the beginning"; std::cout << s.rfind("ar") << '\n'; // Search from the end } /* 2 */