Answers for "how to declare map in cpp"

C++
1

map in cpp

#include<bits/stdc++.h>
using namespace std;

int main()
{
  map<string,int>mapa;
  for(int i=0;i<10;i++){
    int x;
    string s;
    cin>>x>>s;
    mapa.insert({s,x});
    }
  for(auto [x,y]:mapa){
    cout<<x<<" "<<y<<'n';
  }
}
Posted by: Guest on June-15-2021
2

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;
}
Posted by: Guest on December-04-2020

Browse Popular Code Answers by Language