Map count in C++
Level 3102 keystrokes
map::count returns how many entries have the given key. Keys in a map are unique, so the result is 1 if the key exists and 0 if not: "a" gives 1 and "c" gives 0.
C++ code
1map<string, int> m = {{"a", 1}, {"b", 2}};// "a" is a key: prints 12cout << m.count("a") << endl;// "c" is not: prints 0; unlike m["c"], count does not insert the key3cout << m.count("c") << endl;Output
1 0
Practice typing this code. Results are not recorded in the rankings.
Symbols in this code
The symbols you type in this C++ code and how often they appear.
<× 9"× 8,× 4;× 3{× 3}× 3.× 2(× 2)× 2=× 1