#include #include using namespace std; int main() { map _map; _map[0] = 1; _map[1] = 2; _map[10] = 10; map::iterator iter; iter = _map.begin(); while(iter != _map.end()) { cout << iter->first << " : " << iter->second << endl; iter++; } // 也可以使用for循环遍历 return 0; }
程序的运行结果为:
注意: 如果使用for循环遍历map,不能写成 ‘<’ 的形式
上一篇 Ubuntu配置Intel oneAPI DPC++/C++ Compiler(icpc/icc)
下一篇 7 注释和标识符
版权所有 (c)2021-2022 MSHXW.COM
ICP备案号:晋ICP备2021003244-6号