c++ map key exists

#include <iostream>
#include <map>

int main() {
    std::map<int, std::string> myMap;

    // Insert key-value pairs into the map
    myMap[1] = "One";
    myMap[2] = "Two";
    myMap[3] = "Three";

    // Check if a key exists in the map
    int keyToCheck = 2;
    auto it = myMap.find(keyToCheck);

    // Check if the iterator points to the end of the map
    if (it != myMap.end()) {
        // Key exists, print the corresponding value
        std::cout << "Key " << keyToCheck << " exists. Value: " << it->second << std::endl;
    } else {
        // Key doesn't exist
        std::cout << "Key " << keyToCheck << " does not exist." << std::endl;
    }

    return 0;
}