C ++ method to traverse map

C ++ method to traverse map

C ++ is required to access the container iterators instead of the subscript.

c++98

    map<string, int>::iterator it;
    for (it = m2.begin(); it != m2.end(); it++) {
        string s = it->first;
        printf("%s %d\n", s.data(), it->second);
    }

c ++ after 11

for(auto it : map1){
	cout << it.first <<" "<< it.second <<endl;
}
Published 23 original articles · won praise 5 · Views 1840

Guess you like

Origin blog.csdn.net/QQ275176629/article/details/104258974