I'v echecked before how to delete a vector entry, but that was to go through the whole vector one element at a time. I was wandering if I can erase the last vector entry if it's equal to something in particular.
I'm trying this:
Code:
if(strncmp(SAD.vectDL[SAD.vectDL.size() - 1].Param, "ENDL", 4) == 0)
{
iterator = vars.vectParmSelectedS.begin();
while(iterator != vars.vectParmSelectedS.end())
{
if(strncmp(SAD.vectDL[SAD.vectDL.size() - 1].Param, "ENDL", 4) == 0)
iterator = vars.vectParmSelectedS.erase(iterator);
else
++iterator;
}
}
So if the last entry in the vector is "ENDL" I want to delete it. In this case I got hrough the whole vector looking for that entry again.
There must be a less painful way to delete an entry. Ex: can I use the index of the last entry somehow?
to avoid doing all of this, is there a swap function that I can use to swap the last entry with another on in the vector?