C++ set end() Function
Example
Loop through a set with an iterator:
set<string> cars = {"Volvo", "BMW", "Ford", "Mazda"};
for (auto it = cars.begin(); it != cars.end(); ++it) {
cout << *it << "\n";
}
Definition and Usage
The end() function returns an iterator (a pointer-like object that points to an element) to the position after the last element of a set.
It does not point to a real element, so you cannot use it to read a value. It is used to know when a loop should stop, and to check if find() found a value.
The end function is defined in the <set> header file.
Syntax
set.end()
Parameter Values
None.
Technical Details
| Returns: | An iterator pointing to the position after the last element of the set. |
|---|
Related Pages
Read more about sets in our Sets Tutorial.