vector::rend

Returns a reverse_iterator that points to one before the first element in the vector.

const_reverse_iterator rend( ) const; 
reverse_iterator rend( );

A reverse_iterator that points to one before the first element in the 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 element object cannot be modified. If the return value of rend is assigned to a reverse_iterator, then the element can be modified.

The value returned by rend should not be dereferenced.

// vector_rend.cpp
// compile with: /EHsc
#include <vector>
#include <iostream>
using namespace std;
int main( )
{
      
   vector<int> vec;
    vector<int>::reverse_iterator rpos;

    vec.push_back(1);
    vec.push_back(2);

    // Iterate from the last element to the first
    for (rpos = vec.rbegin(); rpos != vec.rend(); ++rpos)
    {
        cout << *rpos << endl;
    }     }
2
1

Header: <vector>

Namespace: std

Was this page helpful?
(1500 characters remaining)
Thank you for your feedback
Show:
© 2015 Microsoft