Loop through multimap and print out value key pair : multimap interator « map multimap « C++ Tutorial






#include <iostream>
using std::cout;
using std::endl;

#include <map>

int main()
{
   std::multimap< int, double, std::less< int > > pairs; // declare the multimap pairs

   // insert two value_type objects in pairs
   pairs.insert( std::multimap< int, double, std::less< int > >::value_type( 15, 2.7 ) );
   pairs.insert( std::multimap< int, double, std::less< int > >::value_type( 15, 99.3 ) );

   cout << "Multimap pairs contains:\nKey\tValue\n";

   // use const_iterator to walk through elements of pairs
   for ( std::multimap< int, double, std::less< int > >::const_iterator iter =pairs.begin();
      iter != pairs.end(); ++iter )
      cout << iter->first << '\t' << iter->second << '\n';


   cout << endl;
   return 0;
}
Multimap pairs contains:
Key     Value
15      2.7
15      99.3








23.14.multimap interator
23.14.1.const_iterator for multimap
23.14.2.Loop through multimap and print out value key pair