- 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
推薦閱讀
- 從零構建知識圖譜:技術、方法與案例
- Java編程指南:基礎知識、類庫應用及案例設計
- Java Web程序設計任務教程
- Learning SciPy for Numerical and Scientific Computing(Second Edition)
- Python深度學習:基于TensorFlow
- 低代碼平臺開發實踐:基于React
- 機器學習與R語言實戰
- Buildbox 2.x Game Development
- 運維前線:一線運維專家的運維方法、技巧與實踐
- SEO教程:搜索引擎優化入門與進階(第3版)
- SQL Server on Linux
- Flink核心技術:源碼剖析與特性開發
- ArcPy and ArcGIS(Second Edition)
- 詩意的邊緣
- R語言與網站分析