Skip to content

Maps: look up by key

Read · 1 of 5

A map is a dictionary

map<string, int> count; stores an int for each string key. count["mango"] reads or changes the value for "mango".

A key you haven't used yet starts at 0, so count[word]++ counts things in one line. A map keeps its keys sorted.