C++遍歷map方法
C++中訪問容器需要使用迭代器,而非下標。
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++11以後
for(auto it : map1){
cout << it.first <<" "<< it.second <<endl;
}