how to print map values in c++ code example
Example 1: prints all the keys and values in a map c++
for (auto x : m) {
cout << x.first << " " << x.second << "\n";
}
Example 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;
map<char, int> cnt;
string x = "Sumant Tirkey";
for(char c:x){
cnt[c]++;
}
cout<< cnt['a']<<" "<<cnt['z']<<endl;
}
int main() {
mapDemo();
return 0;
}