Skip to content

Instantly share code, notes, and snippets.

@tanvir002700
Created April 16, 2016 16:01
Show Gist options
  • Save tanvir002700/5a29485475dec4a8d5230aeb24a55109 to your computer and use it in GitHub Desktop.
Save tanvir002700/5a29485475dec4a8d5230aeb24a55109 to your computer and use it in GitHub Desktop.
#include<iostream>
#include<map>
using namespace std;
int main()
{
map<char,int>Map;
map<char,int>::iterator it;
for(char c='a';c<='j';c++)
{
int value=(int)c;
Map[c]=value;
}
cout<<"Map size: "<<Map.size()<<endl;
cout<<"Map key value: \n";
for(it=Map.begin();it!=Map.end();it++)
{
cout<<"Key-> "<<(*it).first<<" value-> "<<(*it).second<<endl;
}
cout<<"Key a value: "<<Map['a']<<endl;
if(Map.find('a')!=Map.end())cout<<"key 'a' found"<<endl;
else cout<<"key 'a' not found"<<endl;
if(Map.find('z')!=Map.end())cout<<"key 'z' found"<<endl;
else cout<<"key 'z' not found"<<endl;
Map.clear();
cout<<"Is map empty: "<<Map.empty()<<endl;
return 0;
}
Map size: 10
Map key value:
Key-> a value-> 97
Key-> b value-> 98
Key-> c value-> 99
Key-> d value-> 100
Key-> e value-> 101
Key-> f value-> 102
Key-> g value-> 103
Key-> h value-> 104
Key-> i value-> 105
Key-> j value-> 106
Key a value: 97
key 'a' found
key 'z' not found
Is map empty: 1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment