#include <iostream>
#include <unordered_map>
int main() {
// Step 1: Include necessary header files
// #include <iostream>: Provides input/output stream functions
// #include <unordered_map>: Includes the unordered_map container class
// Step 2: Create an unordered_map
std::unordered_map<int, std::string> myMap;
// Step 3: Insert elements into the unordered_map
myMap.insert({1, "One"});
myMap.insert({2, "Two"});
myMap.insert({3, "Three"});
// Step 4: Access elements in the unordered_map
std::cout << "Value at key 2: " << myMap[2] << std::endl;
// Step 5: Check if a key is present in the unordered_map
if (myMap.find(3) != myMap.end()) {
std::cout << "Key 3 is present." << std::endl;
}
// Step 6: Remove an element from the unordered_map
myMap.erase(1);
// Step 7: Iterate through the unordered_map
for (const auto& pair : myMap) {
std::cout << "Key: " << pair.first << ", Value: " << pair.second << std::endl;
}
// Step 8: Check if the unordered_map is empty
if (myMap.empty()) {
std::cout << "The unordered_map is empty." << std::endl;
} else {
std::cout << "The unordered_map is not empty." << std::endl;
}
// Step 9: Get the size of the unordered_map
std::cout << "Size of the unordered_map: " << myMap.size() << std::endl;
return 0;
}