C++遍历map方法

C++遍历map方法

C++中访问容器需要使用迭代器,而非下标。

c++98

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

c++11以后

for(auto it : map1){
	cout << it.first <<" "<< it.second <

你可能感兴趣的:(java,java,后端)