C++ vector rend() function
Example
List the items of a vector in reverse:
vector<string> cars = {"Volvo", "BMW", "Ford", "Mazda"};
vector<string>::reverse_iterator it;
for (it = cars.rbegin(); it != cars.rend(); ++it) {
cout << *it << "\n";
}
Try it Yourself »
Definition and Usage
The rend()
function returns a reverse iterator pointing to a position right before the first element of a vector. This represents the end of the vector when iterating in reverse.
Note: The reverse iterator is pointing to one position before the first element. To access the first element, use vector.rend() - 1
.
Syntax
vector.rend();
Parameter Values
None.
Technical Details
Returns: | A reverse iterator pointing to the position in the vector that represents the end when iterating in reverse. |
---|
Related Pages
Read more about vectors in our Vector Tutorial.
Read more about iterators in our Iterators Tutorial.