Mega Code Archive

 
Categories / C++ / Data Structure
 

Cycle through a map using an iterator

#include <iostream> #include <map> using namespace std; int main() {   map<char, int> mapObject;   int i;   for(i = 0; i < 26; i++)     mapObject.insert(pair<char, int>('A' + i, 65 + i));   map<char, int>::iterator p;      for(p = mapObject.begin(); p != mapObject.end(); p++) {     cout << p->first << " has ASCII value of ";     cout << p->second << endl;   }   return 0; }