- 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
推薦閱讀
- Google Flutter Mobile Development Quick Start Guide
- Python數(shù)據(jù)分析基礎
- 跟老齊學Python:輕松入門
- Java 9 Programming Blueprints
- Python從入門到精通(精粹版)
- Git高手之路
- Apache Spark Graph Processing
- 假如C語言是我發(fā)明的:講給孩子聽的大師編程課
- Android 應用案例開發(fā)大全(第3版)
- HTML5+CSS3 Web前端開發(fā)技術(第2版)
- Python入門很輕松(微課超值版)
- FPGA嵌入式項目開發(fā)實戰(zhàn)
- 實戰(zhàn)Java高并發(fā)程序設計(第2版)
- 現(xiàn)代CPU性能分析與優(yōu)化
- Node.js 6.x Blueprints