make a dictionary out of a multimap : multimap « map multimap « C++ Tutorial






#include <algorithm>
#include <iostream>
#include <map>
#include <utility>

using namespace std;

int main( )
{
   const char* word[] = { "A", "B", "C", "D","E" };
   const char* clue[] = { "a", "b","c", "d","e" };

   map<string,string> dictionary1;
   transform( word, word+sizeof(word)/sizeof(word[0]), clue,inserter( dictionary1, dictionary1.end() ),make_pair<string,string> );

   typedef multimap<string,string> Dictionary;
   Dictionary dictionary2( dictionary1.begin(),dictionary1.end() );
   dictionary2.insert( make_pair( "POPS", "Bursts" ) );
   dictionary2.insert( make_pair( "POPS", "Fathers" ) );
   dictionary2.insert( make_pair( "ADAM", "Madam" ) );

   pair<Dictionary::iterator,Dictionary::iterator> range = dictionary2.equal_range( "POPS" );
   for( Dictionary::iterator i = range.first; i != range.second; ++i )
      cout << "\nPOPS - " << i->second;

   for( Dictionary::iterator i = dictionary2.begin();
      i != dictionary2.end(); ++i )
      cout << i->first << " - " << i->second << endl;
}








23.11.multimap
23.11.1.A multimap can store duplicates
23.11.2.multimap can return the number of pairs with the same key
23.11.3.Instantiating an STL map and multimap (Key Type: integer, Value Type: string)
23.11.4.make a dictionary out of a multimap