C++ 23 · Containers and algorithms

Use a hash map

Look up values by key. contains is available since C++20.

std::unordered_map<std::string, int> ages{{"Ada", 36}, {"Grace", 45}};
ages["Linus"] = 28;
if (ages.contains("Ada")) std::cout << ages.at("Ada") << '\n';

Official C++ 23 documentation

More containers and algorithms commands

All containers and algorithms commands · C++ 23 cheatsheet

Was this page helpful?