mardi 30 juin 2015

Vectors in c++, contain unique elements

I have a program here that is supposed to remove all repeating elements in a vector and only have unique elements.

void simplifyVector(vector<string> i){

/*vector<string>*/;

sort(i.begin(), i.end());

auto iter = unique(i.begin(), i.end());

while (iter != i.end())
{
    i.erase(iter);
}



  for (const auto &s : i)
    {
        cout << s << " ";
    }
    cout << endl;


}

Sadly, i get the run time error vector iterator incompatible .

Help please!

Aucun commentaire:

Enregistrer un commentaire