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';
}
}
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';
}
}
map at function c++
// map::at
#include <iostream>
#include <string>
#include <map>
int main ()
{
std::map<std::string,int> mymap = {
{ "alpha", 0 },
{ "beta", 0 },
{ "gamma", 0 } };
mymap.at("alpha") = 10;
mymap.at("beta") = 20;
mymap.at("gamma") = 30;
for (auto& x: mymap) {
std::cout << x.first << ": " << x.second << 'n';
}
return 0;
}
map in cpp
#include <map>
// empty map container
map<int, int> gquiz1;
// insert elements in random order
gquiz1.insert(pair<int, int>(1, 40));
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;
}
Copyright © 2021 Codeinu
Forgot your account's password or having trouble logging into your Account? Don't worry, we'll help you to get back your account. Enter your email address and we'll send you a recovery link to reset your password. If you are experiencing problems resetting your password contact us