performing an insertion if such key does not already exist.
#include <iostream>
#include <map>
int main()
{
std::map<char, int> letter_counts;
letter_counts['a'];
for(auto& [k,v]: letter_counts) {
std::cout<<k <<", "<<v<<std::endl;
}
std::cout<<"-------------------"<<std::endl;
letter_counts['b'];
for(auto& [k,v]: letter_counts) {
std::cout<<k <<", "<<v<<std::endl;
}
std::cout<<"-------------------"<<std::endl;
letter_counts['a']=1;
for(auto& [k,v]: letter_counts) {
std::cout<<k <<", "<<v<<std::endl;
}
std::cout<<"-------------------"<<std::endl;
letter_counts['a'];
for(auto& [k,v]: letter_counts) {
std::cout<<k <<", "<<v<<std::endl;
}
std::cout<<"-------------------"<<std::endl;
return 0;
}
output:
a, 0
-------------------
a, 0
b, 0
-------------------
a, 1
b, 0
-------------------
a, 1
b, 0
-------------------