std::map iterator
suggest changebegin() returns an iterator to the first element in the container, or end() if the map is empty. Dereferencing end() is undefined.
If a map object is const-qualified, begin() returns a const_iterator. Otherwise, it returns an iterator. Map elements are std::pair<const Key, T>.
// Create a map and insert some values
std::map<char,int> mymap;
mymap['b'] = 100;
mymap['a'] = 200;
mymap['c'] = 300;
// Iterate over all pairs
for (std::map<char,int>::iterator it = mymap.begin(); it != mymap.end(); ++it)
std::cout << it->first << " => " << it->second << '\n';
Output:
a => 200
b => 100
c => 300
Found a mistake? Have a question or improvement idea?
Let me know.
Table Of Contents