int main(){
map<int, int> m;
for (int i = 0; i < 10; i++){
m[i] = i*10;
}
map<int,int>::iterator iter;
iter = m.begin();
while(iter != m.end()){
cout << iter->first << "-" << iter->second << endl;
iter++;
}
for (iter = m.begin();iter != m.end(); iter++){
cout << iter->first << "-" << iter->second << endl;
}
for(auto &it : m){
cout << it.first << "-" << it.second <<endl;
}
//反向遍历,只举一个例子
iter = m.end();
iter--;
while(iter != m.begin()){
cout << iter->first << "-" << iter->second << endl;
iter--;
}
return 0;
}
网友评论