C++ unordered_set end() Function
Example
Use find() and end() to check if "Tesla" exists:
unordered_set<string> cars = {"Volvo", "BMW", "Ford", "Mazda"};
if (cars.find("Tesla") == cars.end()) {
cout << "Tesla is not in the set";
} else {
cout << "Tesla is in the set";
}
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 an unordered set.
It does not point to a real element, so you cannot use it to read a value. It is used to check if find() found a value, and to know when a loop should stop.
The end function is defined in the <unordered_set> header file.
Syntax
unordered_set.end()
Parameter Values
None.
Technical Details
| Returns: | An iterator pointing to the position after the last element of the unordered set. |
|---|
Related Pages
Read more about unordered sets in our Unordered Set Tutorial.