topical media & game development

talk show tell print

professional-program-22-NonModifyingAlgorithms-ForEachBasic.c

? / professional-program-22-NonModifyingAlgorithms-ForEachBasic.c


  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);
  }
  


(C) Æliens 20/2/2008

You may not copy or print any of this material without explicit permission of the author or the publisher. In case of other copyright issues, contact the author.