check if an element is in a map c++

#include <iostream>
#include <map>

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

    // Inserting elements into the map
    myMap[1] = "One";
    myMap[2] = "Two";
    myMap[3] = "Three";
    myMap[4] = "Four";

    // Checking if an element is in the map
    int keyToFind = 3;
    auto it = myMap.find(keyToFind);

    // Checking the result of the find operation
    if (it != myMap.end()) {
        std::cout << "Element with key " << keyToFind << " found. Value: " << it->second << std::endl;
    } else {
        std::cout << "Element with key " << keyToFind << " not found in the map." << std::endl;
    }

    return 0;
}