- 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
推薦閱讀
- 精通Nginx(第2版)
- JavaScript+DHTML語法與范例詳解詞典
- Building Modern Web Applications Using Angular
- R語言經(jīng)典實例(原書第2版)
- Pandas Cookbook
- HoloLens Beginner's Guide
- Java程序設(shè)計與計算思維
- HDInsight Essentials(Second Edition)
- 劍指Java:核心原理與應(yīng)用實踐
- D3.js By Example
- ActionScript 3.0從入門到精通(視頻實戰(zhàn)版)
- Kotlin語言實例精解
- Joomla!Search Engine Optimization
- Web開發(fā)新體驗
- Blender 3D Cookbook