Export (0) Print
Expand All

vector::rend

Returns an iterator that addresses the location succeeding the last element in a reversed vector.

const_reverse_iterator rend( ) const; 
reverse_iterator rend( );

A reverse random-access iterator that addresses the location succeeding the last element in a reversed vector (the location that had preceded the first element in the unreversed vector).

rend is used with a reversed vector just as end is used with a vector.

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

rend can be used to test to whether a reverse iterator has reached the end of its vector.

The value returned by rend should not be dereferenced.

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

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

   for ( v1_rIter = v1.rbegin( ) ; v1_rIter != v1.rend( ) ; v1_rIter++ )
      cout << *v1_rIter << endl;
}
2 1

Header: <vector>

Namespace: std

Community Additions

ADD
Show:
© 2014 Microsoft