algorithm map values

#include <iostream>
#include <map>

int main() {
    // Step 1: Declare a map to store key-value pairs
    std::map<int, std::string> myMap;

    // Step 2: Insert key-value pairs into the map
    myMap.insert(std::make_pair(1, "One"));
    myMap.insert(std::make_pair(2, "Two"));
    myMap.insert(std::make_pair(3, "Three"));

    // Step 3: Access and print values using keys
    std::cout << "Value at key 1: " << myMap[1] << std::endl;
    std::cout << "Value at key 2: " << myMap[2] << std::endl;
    std::cout << "Value at key 3: " << myMap[3] << std::endl;

    // Step 4: Check if a key exists in the map
    int keyToFind = 2;
    if (myMap.find(keyToFind) != myMap.end()) {
        std::cout << "Key " << keyToFind << " found. Value: " << myMap[keyToFind] << std::endl;
    } else {
        std::cout << "Key " << keyToFind << " not found in the map." << std::endl;
    }

    // Step 5: Update the value associated with a key
    myMap[2] = "NewTwo";

    // Step 6: Print the updated value
    std::cout << "Updated value at key 2: " << myMap[2] << std::endl;

    // Step 7: Iterate through all key-value pairs in the map
    std::cout << "All key-value pairs in the map:" << std::endl;
    for (const auto& pair : myMap) {
        std::cout << "Key: " << pair.first << ", Value: " << pair.second << std::endl;
    }

    return 0;
}