-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMap.cpp
More file actions
38 lines (38 loc) · 749 Bytes
/
Map.cpp
File metadata and controls
38 lines (38 loc) · 749 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#include<iostream>
#include<map>
using namespace std;
main()
{
int value;
char key;
map<char,int> MAP;
map<char,int>::iterator p=MAP.begin(),ptr=MAP.begin();
for(int i=0;i<5;i++)
{
cout<<"key n value? :";
cin>>key>>value;
MAP.insert(pair<char,int>(key,value));
ptr++;
}
ptr--;
cout<<ptr->second;
pair<char,int> PAIR('f',7);
// MAP.clear(); -> to clear the map
cout<<" "<<boolalpha<<MAP.empty()<<endl;
//MAP.erase(ptr);
cout<<MAP.size()<<endl;
cout<<MAP[PAIR.first]<<endl;
for(p=MAP.begin();p!=MAP.end();p++)
{
cout<<p->first<<" "<<p->second<<endl;
}
cout<<"press any key :";
char c;
cin>>c;
p=MAP.find(c);
if(p!=MAP.end())
cout<<p->first<<" "<<p->second<<endl;
else
cout<<"no result found";
while(2);
}