Note that in all proposed solutions the keys are unordered (which is fine, why order if there is no need?) If you need them ordered you will need to sort the result
–
David Rodríguez - dribeasJan 15 '12 at 17:04

You may want to iterate through the hash_map, and extract the first element from the pair pointed by current iterator value (the first element of the pair is in fact a key).

// Assuming that hm is an instance of hash_map:
for (auto it = hm.begin(); it != hm.end(); ++it) // for each item in the hash map:
{
// it->first is current key
// ... you can push_back it to a vector<Key> or do whatever you want
}

This is a possible function to extract keys from a hash_map to a vector: