C++ unordered_map end() Function
Example
Use find() and end() to check if the key "Jenny" exists:
unordered_map<string, int> people = {{"John", 32}, {"Adele", 45}, {"Bo", 29}};
if (people.find("Jenny") == people.end()) {
cout << "Jenny is not in the map";
} else {
cout << "Jenny is in the map";
}
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 map.
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 key, and to know when a loop should stop.
The end function is defined in the <unordered_map> header file.
Syntax
unordered_map.end()
Parameter Values
None.
Technical Details
| Returns: | An iterator pointing to the position after the last element of the unordered map. |
|---|
Related Pages
Read more about unordered maps in our Unordered Map Tutorial.