#include#include int main() { std::string str{ "hello" }; // iterate the string in reverse order for(auto it = str.crbegin(); it != str.crend(); ++it) { std::cout << *it; } return 0; }
#includeThis code uses std::reverse to reverse the order of the characters in the string. The crbegin method is used to get a const_reverse_iterator pointing to the last element in the string. Package library: The cpp std string crbegin function is a part of the C++ Standard Library.#include int main() { std::string str{ "hello" }; // reverse the string in-place std::reverse(str.crbegin(), str.crend()); return 0; }