mercredi 27 janvier 2016

Keep the order of unordered_map as we inseart new a key

I inserted the elements to the unordered_map with this code:

    myMap.insert(std::make_pair("A", 10));
    myMap.insert(std::make_pair("B", 11));
    myMap.insert(std::make_pair("C", 12));
    myMap.insert(std::make_pair("D", 13));

But when I used this command to print the keys

for (const auto i : myMap)
{
    cout  << i.first << std::endl;
}

they are not in the same order as I inserted them.

Is it possible to keep the order?

Aucun commentaire:

Enregistrer un commentaire