dimanche 26 mai 2019

Attempting to remove onr item from a vector - removes multiple items instead

I have three items in a vector

A,B,C

If I remove the middle item - Last item gets removed as well. This is my code. I would only like to remove the middle item.

auto it = std::find_if(myVec.begin(), myVec.end(), [itemData](const foo& data){
            return data.getName() == itemData;
        });

    if(it != myVec.end()){
        myVec.erase(it, myVec.end());
    }

Any suggestion on what I might be doing wrong ?

Aucun commentaire:

Enregistrer un commentaire