-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmap.cpp
More file actions
31 lines (22 loc) · 697 Bytes
/
map.cpp
File metadata and controls
31 lines (22 loc) · 697 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
#include <iostream>
#include <map>
using namespace std;
int main() {
map<int, int> mp;
// Diffrent ways to store data in a map
mp.insert({1, 5});
mp.insert(make_pair(4, 5));
mp.insert(pair<int, int>(7, 8));
mp[9] = 4;
mp[2] = 15;
mp[3] = 1;
for (auto i : mp)
cout << "Key: " << i.first << " | Value: " << i.second << endl;
mp.erase(9);
for (auto i : mp)
cout << "Key: " << i.first << " | Value: " << i.second << endl;
if (mp.find(1) != mp.end()) cout << "An element with key 1 is found and it's value is " << mp[1];
else cout << "There is no element with a key of 1";
mp.clear(); // Clear the map
return 0;
}