VOOZH about

URL: https://www.geeksforgeeks.org/cpp/string-rbegin-and-string-rend-in-cpp/

⇱ string::rbegin() and string::rend() in C++ - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

string::rbegin() and string::rend() in C++

Last Updated : 23 Jul, 2025

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.

Syntax

str.rbegin()

where str is the name of the string.

Parameter

  • This function does not accept any parameter.

Return value

  • It 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.

Syntax

string_name.rend()

Parameter

  • This function does not accept any parameter.

Return value

  • It returns a reverse iterator pointing to the theoretical character before the first character in the string.

Example of string::rbegin() and string::rend()


Output
Practice With GfG


Comment
Article Tags: