Export (0) Print
Expand All

vector::crend

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

const_reverse_iterator crend( ) const;

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

crend is used with a reversed vector just as vector::cend is used with a vector.

With the return value of crend (suitably decremented), the vector object cannot be modified.

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

The value returned by crend should not be dereferenced.

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

int main( )
{
   using namespace std;   
   vector <int> v1;
   vector <int>::const_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