O'Reilly logo

Mastering C++ Programming by Jeganathan Swaminathan

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required