C++ set rend() Function
Example
Loop through a set in reverse order:
set<string> cars = {"Volvo", "BMW", "Ford", "Mazda"};
for (auto it = cars.rbegin(); it != cars.rend(); ++it) {
cout << *it << "\n";
}
Definition and Usage
The rend() function returns a reverse iterator (an iterator that moves backwards) to the position before the first element of a set.
It does not point to a real element, so you cannot use it to read a value. It is used together with rbegin() to know when a reverse loop should stop.
The rend function is defined in the <set> header file.
Syntax
set.rend()
Parameter Values
None.
Technical Details
| Returns: | A reverse iterator pointing to the position before the first element of the set. |
|---|
Related Pages
Read more about sets in our Sets Tutorial.