Share via


vector::rbegin

Returns an iterator to the first element in a reversed vector.

reverse_iterator rbegin( ); 
const_reverse_iterator rbegin( ) const;

Return Value

A reverse random-access iterator addressing the first element in a reversed vector or addressing what had been the last element in the unreversed vector.

Remarks

If the return value of rbegin is assigned to a const_reverse_iterator, the vector object cannot be modified. If the return value of rbegin is assigned to a reverse_iterator, the vector object can be modified.

Example

// vector_rbegin.cpp
// compile with: /EHsc
#include <vector>
#include <iostream>

int main( )
{
   using namespace std;   
   vector <int> v1;
   vector <int>::iterator v1_Iter;
   vector <int>::reverse_iterator v1_rIter;
   
   v1.push_back( 1 );
   v1.push_back( 2 );

   v1_Iter = v1.begin( );
   cout << "The first element of vector is "
        << *v1_Iter << "." << endl;

   v1_rIter = v1.rbegin( );
   cout << "The first element of the reversed vector is "
        << *v1_rIter << "." << endl;
}
The first element of vector is 1.
The first element of the reversed vector is 2.

Requirements

Header: <vector>

Namespace: std

See Also

Reference

vector Class

Standard Template Library