This question already has an answer here:
- Erasing elements from a vector 5 answers
My applications requires to iterate over a vector and delete certain elements which doesnt satisfy the requirements. Which is the most correct way? I believe the following way is incorrect.Reason: I am getting segmentation fault.
std::vector<ObjectX> vec1;
//Fill in vec1
std::vector<ObjectX>::iterator itVec1 = vec1.begin();
for(;itVec1 != vec1.end(); ++itVec1) {
if (Oracle(*itVec1)) vec1.erase(itVec1);
}
Aucun commentaire:
Enregistrer un commentaire