-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathunordered_map.cpp
41 lines (31 loc) · 941 Bytes
/
unordered_map.cpp
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
39
40
41
#include<iostream>
#include<unordered_map>
using namespace std;
int main()
{
unordered_map<string,double> um;
//Declaring umap to string and double type
//key will string and mapped value will be of double type
//inserting values by using [] operator
um["PI"] = 3.14;
um["root2"] = 1.414;
um["root3"] = 1.732;
um["log10"] = 2.302;
//now insert value by using insert function
um.insert(make_pair("e",5645));
string key;
cout<<"ENter the key you want to search for!"<<endl;
cin>>key;
//if key nnot found in map iterator to end is returened
if(um.find(key)==um.end())
cout << key << "not found\n\n";
else
cout << "Found" << key << "\n\n";
//now iterating from all over the map
unordered_map<string, double>:: iterator itr;
cout << "\n All Elements : \n";
for (itr = um.begin(); itr != um.end(); itr++)
{
cout<< itr->first << " " << itr->second << endl;
}
}