官术网_书友最值得收藏!

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
主站蜘蛛池模板: 罗山县| 拉萨市| 历史| 泸定县| 新昌县| 仁怀市| 阜平县| 崇阳县| 奉新县| 威远县| 阿坝| 汝城县| 鄂伦春自治旗| 乌拉特中旗| 高阳县| 淳安县| 海晏县| 霍邱县| 鄂温| 奉新县| 东兰县| 建昌县| 蕲春县| 巴马| 大安市| 枣阳市| 潮安县| 丽江市| 容城县| 前郭尔| 黔南| 安塞县| 彭阳县| 张北县| 霍城县| 仁布县| 明溪县| 景东| 阳泉市| 临猗县| 荃湾区|