Tsallaka zuwa abun ciki
Justice Tech School

map, unordered_map and multimap

map keeps keys sorted, unordered_map uses hashing and is usually faster, and multimap allows duplicate keys. Use find, count, insert and operator[].

Example
#include <unordered_map>
map<string, int> m = {{"b", 2}, {"a", 1}};
m["c"] = 3;
for (auto &[k, v] : m) cout << k << v << " ";
cout << "\n";
unordered_map<string, int> u;
for (string w : {"go", "is", "go"}) u[w]++;
cout << u["go"] << " " << u.count("zzz") << "\n";

Result

a1 b2 c3 
2 0

Exercise

Is the key present?

m.("a")

Quiz Test

Which keeps keys sorted?

These free lessons are for learning. Join a full course for projects, mentor feedback and a verified certificate.