#include <iostream>
#include <unordered_map>
int main() {
// Step 1: Create an unordered_map
std::unordered_map<int, std::string> myHashMap;
// Step 2: Insert key-value pairs into the unordered_map
myHashMap.insert(std::make_pair(1, "One"));
myHashMap.insert(std::make_pair(2, "Two"));
myHashMap.insert(std::make_pair(3, "Three"));
// Step 3: Access elements using the subscript operator []
std::cout << "Value at key 2: " << myHashMap[2] << std::endl;
// Step 4: Check if a key exists in the unordered_map
int keyToFind = 3;
auto it = myHashMap.find(keyToFind);
if (it != myHashMap.end()) {
std::cout << "Key " << keyToFind << " found. Value: " << it->second << std::endl;
} else {
std::cout << "Key " << keyToFind << " not found." << std::endl;
}
// Step 5: Update the value associated with a key
myHashMap[2] = "New Two";
// Step 6: Remove a key-value pair from the unordered_map
int keyToRemove = 1;
myHashMap.erase(keyToRemove);
// Step 7: Print all key-value pairs in the unordered_map
for (const auto& entry : myHashMap) {
std::cout << "Key: " << entry.first << ", Value: " << entry.second << std::endl;
}
return 0;
}