First page Back Continue Last page Overview Graphics
“Get next”/for iterator in C++
std::map<string, int> m;
std::map<string, int>::iterator it;
m["Fred"] = 5;
m["Bob"] = 3;
for (it = m.begin(); it != m.end(); ++it)
{
std::cout << it->first << “:” << it->second << std::endl;
}
Notes:
C++ map elements are returned sorted. The sorting function is a template parameter. It's part of the container's data type.
Contrast this with Perl, where the keys must be manually sorted.