1//assuming your variables are called : variables_
2#include <map>
3#include <string>
4
5std::map<int, std::string> map_;
6map_[1] = "mercury";
7map_[2] = "mars";
8map_.insert(std::make_pair(3, "earth"));
9//either synthax works to declare a new entry
10
11return map_[2]; //here, map_[2] will return "mars"
1#include <bits/stdc++.h>
2#include <iostream>
3#include <map>
4using namespace std;
5void mapDemo(){
6 map<int, int> A;
7 A[1] = 100;
8 A[2] = -1;
9 A[3] = 200;
10 A[100000232] = 1;
11 //to find the value of a key
12 //A.find(key)
13
14 //to delete the key
15 //A.erase(key)
16
17 map<char, int> cnt;
18 string x = "Sumant Tirkey";
19
20 for(char c:x){
21 cnt[c]++;//map the individual character with it's occurance_Xtimes
22 }
23
24 //see how many times a and z occures in my name
25 cout<< cnt['a']<<" "<<cnt['z']<<endl;
26
27}
28
29int main() {
30 mapDemo();
31 return 0;
32}