#include#include int main() { std::string str = "Hello World!"; std::size_t pos = str.rfind("World"); if (pos != std::string::npos) { std::cout << "Found 'World' at position " << pos << std::endl; } else { std::cout << "'World' not found" << std::endl; } return 0; }
Found 'World' at position 6
#include#include int main() { std::string str = "Hello World!"; std::size_t pos = str.rfind("world"); if (pos != std::string::npos) { std::cout << "Found 'world' at position " << pos << std::endl; } else { std::cout << "'world' not found" << std::endl; } return 0; }
'world' not foundIn this example, the rfind function is used to search for the last occurrence of the substring "world" in the string "Hello World!". However, since the function is case-sensitive, it returns std::string::npos since the substring is not found. Package Library: Standard Library