std::unordered_map is a container in the C++ Standard Library that stores key-value pairs in an unordered manner. It provides constant time complexity O(1) for accessing, inserting, and erasing elements in the map.
std::cout << "Alice is " << ages.at("Alice") << " years old.\n";
ages.at("Bob")++;
for (const auto& [name, age] : ages) { std::cout << name << " is " << age << " years old.\n"; }
return 0; }
In this example, we define an unordered_map named ages that stores the ages of three people. We use the at() function to access the age of Alice and then increment the age of Bob by 1. Finally, we use a range-based for loop to iterate over all the elements in the map and print out their names and ages.
Package library: std (C++ Standard Library).
C++ (Cpp) unordered_map::at - 30 examples found. These are the top rated real world C++ (Cpp) examples of std::unordered_map::at extracted from open source projects. You can rate examples to help us improve the quality of examples.