Get iterator from a map : map iterator « Map Multimap « C++






Get iterator from a map

  
#include <iostream>
#include <map>
using namespace std;
   
int main()
{
  map<char, int> m;
  int i;
   
  for(i=0; i<26; i++) {
    m.insert(pair<char, int>('A'+i, 65+i));
  }
   
  char ch;
  cout << "Enter key: ";
  cin >> ch;
   
  map<char, int>::iterator p;
 
  p = m.find(ch);
  if(p != m.end())
    cout << "Its ASCII value is  " << p->second;
  else
    cout << "Key not in map.\n";
   
  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.Map Iterators
7.Use while to loop through a map