Find the value with a given key : map find « Map Multimap « C++






Find the value with a given key

  
#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.Map find
2.map: find_if
3.Find product in a map by its number
4.Find product in a map by its type
5.find all elements in a map by value
6.map find with custom object
7.map look up