- Mastering C++ Programming
- Jeganathan Swaminathan
- 149字
- 2021-07-02 18:28:53
Multimap
A multimap works exactly as a map, except that a multimap container will allow multiple values to be stored with the same key.
Let's explore the multimap container with a simple example:
#include <iostream>
#include <map>
#include <vector>
#include <iterator>
#include <algorithm>
using namespace std;
int main() {
multimap< string, long > contacts = {
{ "Jegan", 2232342343 },
{ "Meena", 3243435343 },
{ "Nitesh", 6234324343 },
{ "Sriram", 8932443241 },
{ "Nitesh", 5534327346 }
};
auto pos = contacts.find ( "Nitesh" );
int count = contacts.count( "Nitesh" );
int index = 0;
while ( pos != contacts.end() ) {
cout << "\nMobile number of " << pos->first << " is " <<
pos->second << endl;
++index;
if ( index == count )
break;
}
return 0;
}
The program can be compiled and the output can be viewed with the following commands:
g++ main.cpp -std=c++17
./a.out
The output of the program is as follows:
Mobile number of Nitesh is 6234324343
Mobile number of Nitesh is 5534327346
推薦閱讀
- Facebook Application Development with Graph API Cookbook
- Kubernetes實戰
- 碼上行動:零基礎學會Python編程(ChatGPT版)
- Visual Basic程序設計(第3版):學習指導與練習
- Python爬蟲開發與項目實戰
- 基于ARM Cortex-M4F內核的MSP432 MCU開發實踐
- 軟件供應鏈安全:源代碼缺陷實例剖析
- HTML5開發精要與實例詳解
- 時空數據建模及其應用
- 零基礎C#學習筆記
- PHP項目開發全程實錄(第4版)
- Mastering ASP.NET Core 2.0
- Oracle Database XE 11gR2 Jump Start Guide
- 算法超簡單:趣味游戲帶你輕松入門與實踐
- Ionic3與CodePush初探:支持跨平臺與熱更新的App開發技術