c++ multimap只遍历key
时间: 2024-05-17 10:18:58 浏览: 91
在给定的代码示例中,使用了multimap容器来存储键值对。如果你只想遍历multimap中的键,可以使用下面的方式:
```cpp
multimap<string, int>::iterator it;
for (it = m_map.begin(); it != m_map.end(); ++it)
{
cout << it->first << endl;
}
```
在这个循环中,我们使用迭代器it来遍历multimap容器,it->first表示当前键的值。通过输出it->first,我们可以只遍历并打印multimap中的键。<span class="em">1</span><span class="em">2</span><span class="em">3</span>
#### 引用[.reference_title]
- *1* *2* [C++中遍历multimap](https://blog.csdn.net/Think88666/article/details/85079223)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_1"}}] [.reference_item style="max-width: 50%"]
- *3* [C++ STL(vector+multimap容器)案例](https://download.csdn.net/download/qq_40851561/15837148)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_1"}}] [.reference_item style="max-width: 50%"]
[ .reference_list ]
阅读全文