Skip to content

Commit 14991ce

Browse files
committed
complete map with simple example as well use map methods
1 parent d2c4a71 commit 14991ce

2 files changed

Lines changed: 25 additions & 0 deletions

File tree

Map.cpp

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,30 @@
1+
//! Map is an associative array
2+
13
#include<iostream>
4+
#include<string>
5+
#include<map>
6+
27
using namespace std;
38
int main(){
9+
map<string, int> marksMap;
10+
marksMap["Sumit"] = 98;
11+
marksMap["Kashish"] = 99;
12+
marksMap["Shubh"] = 90;
13+
marksMap["Kajal"] = 95;
14+
15+
//* Insert new person in the map
16+
marksMap.insert({{"Armaan", 99}, {"Anshika", 95}});
17+
18+
map<string, int>::iterator itra;
19+
for (itra = marksMap.begin(); itra != marksMap.end(); itra++){
20+
cout << (*itra).first << " " << (*itra).second << "\n";
21+
}
22+
cout << "The size of map is: " << marksMap.size()<<endl;
23+
cout << "The Max-size of map is: " << marksMap.max_size()<<endl;
24+
cout << "The empty value of map: " << marksMap.empty()<<endl;
25+
26+
auto result = marksMap.emplace("i", 1); // key: "i", value: 1
27+
cout << "Inserted? " << boolalpha << result.second << "\n";
28+
cout << "Key: " << result.first->first << ", Value: "<< result.first->second << "\n";
429
return 0;
530
}

Map.exe

90.2 KB
Binary file not shown.

0 commit comments

Comments
 (0)