In the code snippet above, we declare a map called `myMap` with keys of type `int` and values of type `std::string`. We insert two key-value pairs: `42` and `1337`. By accessing `myMap[42]` and `myMap[1337]`, we obtain the corresponding values: `”Hello,”` and `”world!”`.
The second method of accessing values in a map involves using the find() function. This function returns an iterator pointing to the element if found, or the end iterator if not present. Here’s an example: