string::rbegin() and string::rend() in C++ Last Updated : 23 Jul, 2025 Comments Improve Suggest changes 2 Likes Like Report The std::string::rbegin() and std::string::rend() functions in C++ are used to fetch the reverse iterators to the string. They are the member function of std::string and are used when we want to iterate the string in reverse. In this article, we will learn how to use string::rbegin() and string::rend() in C++.string::rbegin()The string::rbegin() function returns a reverse iterator pointing to the reverse beginning (i.e. last character) of the string.If we increment the reverse iterator, it will move from right to left in the string i.e. it will move from last to second last and so on. It is just opposite to the normal string iterators.Syntaxstr.rbegin()where str is the name of the string.ParameterThis function does not accept any parameter.Return valueIt returns a reverse iterator pointing to the last character in the string.string::rend()The string::rend() is a reverse iterator pointing to the reverse end (i.e. theoretical character which is just before the first character) of the string.Syntaxstring_name.rend()ParameterThis function does not accept any parameter.Return valueIt returns a reverse iterator pointing to the theoretical character before the first character in the string.Example of string::rbegin() and string::rend() C++ // C++ program to illustrate the use of // string::rbegin() and string::rend() function #include <bits/stdc++.h> using namespace std; int main() { string s = "GfG htiW ecitcarP"; // Printing the character of string in // reverse order for (auto it = s.rbegin(); it != s.rend(); it++) cout << *it; return 0; } OutputPractice With GfG Create Quiz Comment A anmolpanxq Follow 2 Improve A anmolpanxq Follow 2 Improve Article Tags : C++ cpp-iterator STL cpp-string Explore C++ BasicsIntroduction to C++3 min readData Types in C++6 min readVariables in C++4 min readOperators in C++9 min readBasic Input / Output in C++3 min readControl flow statements in Programming15+ min readLoops in C++7 min readFunctions in C++8 min readArrays in C++8 min readCore ConceptsPointers and References in C++5 min readnew and delete Operators in C++ For Dynamic Memory5 min readTemplates in C++8 min readStructures, Unions and Enumerations in C++3 min readException Handling in C++12 min readFile Handling in C++8 min readMultithreading in C++8 min readNamespace in C++5 min readOOP in C++Object Oriented Programming in C++8 min readInheritance in C++6 min readPolymorphism in C++5 min readEncapsulation in C++3 min readAbstraction in C++4 min readStandard Template Library(STL)Standard Template Library (STL) in C++3 min readContainers in C++ STL2 min readIterators in C++ STL10 min readC++ STL Algorithm Library3 min readPractice & ProblemsC++ Interview Questions and Answers1 min readC++ Programming Examples4 min read Like