csdn遍历map值
时间: 2023-11-11 10:00:01 浏览: 77
Map遍历方法
遍历map的值可以通过迭代器实现,具体代码如下:
```c++
#include <iostream>
#include <map>
using namespace std;
int main() {
map<int, string> myMap;
myMap[1] = "one";
myMap[2] = "two";
myMap[3] = "three";
for (auto it = myMap.begin(); it != myMap.end(); ++it) {
cout << it->second << endl;
}
return 0;
}
```
输出结果为:
```
one
two
three
```
阅读全文