Maps support several iteration patterns. Choose the one that fits your needs. Range-based for with auto: for (auto& p : myMap) { . } Each p is a pair. Access key with p.first, value with p.second.
Structured bindings (C++17): for (auto& [key, value] : myMap) { . } Cleaner when you need both key and value. Use const auto& if you're not modifying. Iterator-based: for (auto it = myMap.begin(); it != myMap.end(); ++it) { .
} Use this when you need to erase elements while iterating (with care) or need iterator arithmetic.