unordered_map:
Какой-то красивый код (имена переменных упрощены):
Отсюда http://en.cppreference.com/w/cpp/container/unordered_map/operator_at
std::unordered_map<char, int> mu1 {{'a', 27}, {'b', 3}, {'c', 1}};
mu1['b'] = 42; // update an existing value
mu1['x'] = 9; // insert a new value
for (const auto &pair: mu1) {
std::cout << pair.first << ": " << pair.second << '\n';
}
// count the number of occurrences of each word
std::unordered_map<std::string, int> mu2;
for (const auto &w : { "this", "sentence", "is", "not", "a", "sentence", "this", "sentence", "is", "a", "hoax"}) {
++mu2[w]; // the first call to operator[] initialized the counter with zero
}
for (const auto &pair: mu2) {
std::cout << pair.second << " occurrences of word '" << pair.first << "'\n";
}