hash_map
is deprecated, but the same principle applies... you can use a range loop (in this case with an unordered_map)
using auto will make it like:
#include <iostream>
#include <string>
#include <unordered_map>
int main()
{
std::unordered_map<std::string, int> myMap;
myMap.insert(std::pair<std::string, int>("a", 1));
myMap.insert(std::pair<std::string, int>("b", 2));
myMap.insert(std::pair<std::string, int>("c", 3));
myMap.insert(std::pair<std::string, int>("d", 4));
for (const auto& x : myMap)
{
std::cout << "fisrt: " << x.first << ", second: " << x.second << std::endl;
}
std::cin.get();
return 0;
}