for each basic : pair « Map Multimap « C++






for each basic

   
#include <algorithm>
#include <map>
#include <iostream>
using namespace std;

void printPair(const pair<int, int>& elem)
{
  cout << elem.first << "->" << elem.second << endl;
}

int main(int argc, char** argv)
{
  map<int, int> myMap;
  myMap.insert(make_pair(4, 40));
  myMap.insert(make_pair(5, 50));
  myMap.insert(make_pair(6, 60));
  myMap.insert(make_pair(7, 70));
  myMap.insert(make_pair(8, 80));

  for_each(myMap.begin(), myMap.end(), &printPair); 

  return (0);
}
  
    
    
  








Related examples in the same category

1.Inserting pairs of object into map
2.print the maximum number of pairs that DateMap can hold
3.Use map to store the value of the month name and its day number
4.Iterating over the elements of the map and using the current pair option and second elements.
5.Put pairs to map with insert
6.Map for string key and integer value
7.Computing the Median 1
8.Sort a list of int and string pairs
9.Pass output message function to for_each function