#include <iostream> #include <map> using namespace std; int main() { map<int, int> _map; _map[0] = 1; _map[1] = 2; _map[10] = 10; map<int, int>::iterator iter; iter = _map.begin(); while(iter != _map.end()) { cout << iter->first << " : " << iter->second << endl; iter++; } // 也可以使用for循环遍历 /* for(iter = _map.begin(); iter != _map.end(); iter++) { //如果使用for循环遍历map,不能写成 ‘<’ 的形式 cout << iter->first << " : " << iter->second << endl; } */ return 0; }
C++map遍历
最新推荐文章于 2024-02-04 19:25:20 发布