#include#include int main() { std::string str = "hello world"; for (auto rit = str.rbegin(); rit != str.rend(); ++rit) { std::cout << *rit; } std::cout << std::endl; return 0; }
#includeIn this example, we use `std::find()` with `rend()` to search for the last occurrence of the character 'o'. We use `std::distance()` to calculate the position of the found character. The output will be "Last 'o' found at position 6". Package/library: Standard C++ library (included with every C++ compiler).#include #include int main() { std::string str = "the quick brown fox jumps over the lazy dog"; auto pos = std::find(str.rbegin(), str.rend(), 'o'); if (pos != str.rend()) { std::cout << "Last 'o' found at position " << std::distance(pos, str.rend()) << std::endl; } return 0; }