mapping in C++ with template

The map associative container performs fast storage and retrieval of unique keys and associated values. Duplicate keys are not allowed—a single value can be associated with each key. This is called a one-to-one mapping. With a map you specify the key and get back the associated data quickly. A map is also known as an associative array. Providing the key in a map’s subscript operator [] locates the value associated with that key in the map. Insertions and deletions can be made anywhere in a map.

#include<iostream>

using namespace std;

#include<map>

int main()

{

pair<char,int> x;

map<char,int> m;

for(char z='a';z<='z';z++)

{

x.first=z;

x.second=(int)z;

m.insert(x);

}

map<char,int>::iterator it=m.begin();

for(it=m.begin();it!=m.end();it++)

{

cout<<(*it).first<<" "<<(*it).second;

}

}


Output: