6
Q:

how to use map of a map in c++

#include <bits/stdc++.h>
#include <iostream>
#include <map>
using namespace std;
void mapDemo(){
	map<int, int> A;
	A[1] = 100;
	A[2] = -1;
	A[3] = 200;
	A[100000232] = 1;
	//to find the value of a key
	//A.find(key)
	
	//to delete the key
	//A.erase(key)
	
	map<char, int> cnt;
	string x = "Sumant Tirkey";
	
	for(char c:x){
		cnt[c]++;//map the individual character with it's occurance_Xtimes
	}
	
	//see  how many times a and z occures in my name
	cout<< cnt['a']<<" "<<cnt['z']<<endl;
	
} 
	
int main() {
	mapDemo();
	return 0;
}
1
map <typename,map<typename,typename>> mp;
map[key1][key2]=values
1
map <typename,map<typename,typename>> mp;
mp[key1].insert(make_pair(key2,value));
0
//assuming your variables are called : variables_
#include <map>
#include <string>

std::map<int, std::string> map_;
map_[1] = "mercury";
map_[2] = "mars";
map_.insert(std::make_pair(3, "earth"));
//either synthax works to declare a new entry

return map_[2]; //here, map_[2] will return "mars"
0
#include <map>

int main(){
  //new map
  std::map <int,int> myMap;
  myMap[0] = 1;
  myMap[1] = 2;
  myMap[2] = 3;
  myMap[3] = 4;
}
0
#include <map>

// empty map container 
map<int, int> gquiz1; 
  
// insert elements in random order 
gquiz1.insert(pair<int, int>(1, 40)); 
0

New to Communities?

Join the community