Map Iterators : map iterator « Map Multimap « C++






Map Iterators

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

class Data
{
public:
  Data(int val = 0) { mVal = val; }
  int getVal() const { return mVal; }
  void setVal(int val) {mVal = val; }

protected:
  int mVal;
};

int main(int argc, char** argv)
{
  map<int, Data> dataMap;

  dataMap[1] = Data(4);
  dataMap[1] = Data(6);

  for (map<int, Data>::iterator it = dataMap.begin();
       it != dataMap.end(); ++it) {
    cout << it->second.getVal() << endl;
  }
  return (0);
}
  
    
  








Related examples in the same category

1.Use iterator to loop through map and print all elements
2.Loop through map and print all the key/value pair
3.Create int string map and print all element pair
4.const_reverse_iterator from a map
5.const_iterator for map if integer and user-define object
6.Use while to loop through a map
7.Get iterator from a map