File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ // ! Map is an associative array
2+
13#include < iostream>
4+ #include < string>
5+ #include < map>
6+
27using namespace std ;
38int 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}
You can’t perform that action at this time.
0 commit comments