C++ multimap 的插入,遍历,删除
生活随笔
收集整理的這篇文章主要介紹了
C++ multimap 的插入,遍历,删除
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
#include <iostream>
#include <map>
#include <string>using namespace std;int main()
{multimap<string, string> authors;// 插入元素, 引入的頭文件是 mapauthors.insert(make_pair(string("Evin"), // 這個是 Keystring("Hi")));authors.insert(make_pair(string("Evin"), // 跟上面的一樣,是同一個keystring("Hello")));typedef multimap<string, string>::const_iterator mmap_cit;// 第一種遍歷方式mmap_cit beg = authors.lower_bound("Evin");mmap_cit end = authors.upper_bound("Evin");while(beg != end){cout<<beg->second<<endl;++beg;}// 另外一種遍歷方式pair<mmap_cit, mmap_cit> pos = authors.equal_range("Evin");while(pos.first != pos.second){cout<<pos.first->second<<endl;++pos.first;}cout<<authors.erase("Evin")<<endl; // erase 返回刪除的元素個數return 0;
}
利用 multimap 能夠做到一個key, 同一時候相應多個value
總結
以上是生活随笔為你收集整理的C++ multimap 的插入,遍历,删除的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 【Android实战】记录自学自己定义G
- 下一篇: iOS实践04