English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

C++ Usage and example of vector rbegin()

C++ Vector (Container)

rbegin() returns a reverse iterator at the end of the vector

Syntax

The syntax for the vector (vector) "v" is:

reverse_iterator ritr = v.rbegin();

Parameters

It does not contain any parameters.

Return value

It returns a reverse iterator pointing to the last element of the vector (vector).

Example

Let's look at a simple example.

#include<iostream>
#include<vector>
using namespace std;
int main()
{
vector<char> v{'j','a','v','a'};
vector<char>::reverse_iterator rtr;
for(rtr=v.rbegin();rtr!=v.rend();rtr++)
std::cout<< *rtr;
return 0;
}

Output:

avaj

In this example, the rbegin() function is used to obtain the reversed string contained in the vector (vector).

C++ Vector (Container)