Kangaroo
10
Q:

how to iterate through a map in c++

//traditional way (long)
for(map<string,int>::iterator it=m.begin(); it!=m.end(); ++it)
	if(it->second)cout<<it->first<<" ";
//easy way(short) just works with c++11 or later versions
for(auto &x:m)
	if(x.second)cout<<x.first<<" ";
//condition is just an example of use
8

    for (auto i : m) 
        cout << i.first << "   " << i.second << endl; 
6

New to Communities?

Join the community