遍历map集合快捷方式
时间: 2023-11-11 21:00:50 浏览: 97
可以使用C++11中的range-based for循环来遍历map集合,示例代码如下:
```c++
std::map<int, std::string> myMap = {{1, "one"}, {2, "two"}, {3, "three"}};
for (const auto& pair : myMap) {
std::cout << pair.first << ": " << pair.second << std::endl;
}
```
输出结果为:
```
1: one
2: two
3: three
```
阅读全文