C++ map end() Function
Example
Loop through a map with an iterator:
map<string, int> people = {{"John", 32}, {"Adele", 45}, {"Bo", 29}};
for (auto it = people.begin(); it != people.end(); ++it) {
cout << it->first << " is: " << it->second << "\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 map.
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 key.
The end function is defined in the <map> header file.
Syntax
map.end()
Parameter Values
None.
Technical Details
| Returns: | An iterator pointing to the position after the last element of the map. |
|---|
Related Pages
Read more about maps in our Maps Tutorial.