vector rbegin() in C++

rbegin(): It returns a read/write reverse iterator that points to the last element in the vector. 

Note: Iteration is done in reverse element order. 

File: stl_vector.h

Parameter: No parameters required for this function.

Syntax:

vector<data_type>::reverse_iterator iteratorName = vecName.rbegin()

For Example:

vec ={1,2,3,4}

it = vec.rbegin() = > It points to the last element (i.e 4)

Approach

C++

#include <bits/stdc++.h>
using namespace std;

int main()
{
    vector<intvec = {1234};

    vector<int>::reverse_iterator it = vec.rbegin();

    cout << *it << "\n";
    return 0;
}


No comments:

Post a Comment