1//traditional way (long)
2for(map<string,int>::iterator it=m.begin(); it!=m.end(); ++it)
3 if(it->second)cout<<it->first<<" ";
4//easy way(short) just works with c++11 or later versions
5for(auto &x:m)
6 if(x.second)cout<<x.first<<" ";
7//condition is just an example of use
8
1#include <iostream>
2#include <map>
3
4int main() {
5 std::map<int, float> num_map;
6 // calls a_map.begin() and a_map.end()
7 for (auto it = num_map.begin(); it != num_map.end(); ++it) {
8 std::cout << it->first << ", " << it->second << '\n';
9 }
10}