#include#include int main() { std::string str = "Hello World!"; for(auto it = str.rbegin(); it != str.rend(); ++it) { std::cout << *it; } return 0; }
#includeIn this example, we use the function `find_last_of()` which returns the position of last occurrence of the specified character in the string. We use `rend()` to start the search from the end of the string. Package/Library: `STL` (Standard Template Library) is the C++ package/library that contains the `string` class and its member functions.#include int main() { std::string str = "The quick brown fox jumps over the lazy dog"; auto pos = str.find_last_of('o'); std::cout << "Last occurrence of 'o' at position: " << (pos == std::string::npos ? -1 : pos) << std::endl; return 0; }