-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMap.cpp
More file actions
30 lines (25 loc) · 963 Bytes
/
Copy pathMap.cpp
File metadata and controls
30 lines (25 loc) · 963 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
//! Map is an associative array
#include<iostream>
#include<string>
#include<map>
using namespace std;
int main(){
map<string, int> marksMap;
marksMap["Sumit"] = 98;
marksMap["Kashish"] = 99;
marksMap["Shubh"] = 90;
marksMap["Kajal"] = 95;
//* Insert new person in the map
marksMap.insert({{"Armaan", 99}, {"Anshika", 95}});
map<string, int>::iterator itra;
for (itra = marksMap.begin(); itra != marksMap.end(); itra++){
cout << (*itra).first << " " << (*itra).second << "\n";
}
cout << "The size of map is: " << marksMap.size()<<endl;
cout << "The Max-size of map is: " << marksMap.max_size()<<endl;
cout << "The empty value of map: " << marksMap.empty()<<endl;
auto result = marksMap.emplace("i", 1); // key: "i", value: 1
cout << "Inserted? " << boolalpha << result.second << "\n";
cout << "Key: " << result.first->first << ", Value: "<< result.first->second << "\n";
return 0;
}