Re: std::vectpr "Replace" Function?
On 10/16/2014 7:29 PM, MikeCopeland wrote:
Is there no "replace" function for a std::vector? I know that I can
modify a specific vector object by using the .at() operator or the []
indexing, but that's not really what I after. I have the following
declarations:
struct Display
{
int offset;
char dCode;
string p1, p3, p8;
} dispWork;
vector<Display> dispVect;
vector<Display>::iterator dIter;
for(dIter = dispVect.begin(); dIter != dispVect.end(); dIter++)
the increment should not happen if you erase. Move it inside the
loop body and only perform it if *not* condition1.
{
if(condition1) dIter = dispVect.erase(dIter);
else if(condition2) dispVect.replace(dispWork); //????
}
After populating the vector, I wish to use the iterator to walk
through the vector tp delete or change certain elements. I don't want
to use [] indexing during this process because I'm also erasing/removing
elements.
....incorrectly!
> This combined processing will fail by invalidating the
iterator when I delete elements, so I'd prefer to use some "replace"
function for the vector elements I'm saving and changing.
What Juha suggested *is* how you replace. Make sure the rest is OK.
There doesn't seem to be any STL function that accomodates my needs
here...or am I wrong? Please advise. TIA
V
--
I do not respond to top-posted replies, please don't ask