dimanche 29 mai 2016

How do I convert from an unsorted vector to a set?

So I'm trying to convert my vector to a set like this:

 set<int> mySet(myVector.begin(), myVector.end()); 

(My original vector is unsorted and has many duplicates)

How come when I output the contents of my set it still has duplicates and is unsorted?

This is how I output it:

 for(set<int>::iterator x = mySet.begin(); x!=mySet.end(); x++)
       {cout<<*x<<endl;}

Also I would appreciate if someone could give me a good link to find information like this because I honestly tried to find an explanation but couldn't.

Aucun commentaire:

Enregistrer un commentaire