Delen via


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( );

Return Value

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

Remarks

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.

Example

// 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

Requirements

Header: <vector>

Namespace: std

See Also

Reference

vector Class

Standard Template Library