Removing an element from a vector
I need to remove element #idx from vector v. How is this done? Like this? v.erase(&v.front()+idx);
"On a long enough timeline the survival rate of everyone drops to zero"
- Fight Club
error C2678: binary ''+'' : no operator defined which takes a left-hand operand of type ''struct voter'' (or there is no acceptable conversion)
quote:Original post by emileejIt doesn''t work?
I need to remove element #idx from vector v. How is this done? Like this? v.erase(&v.front()+idx);
Google says...
Anyway, from what I can see, really, unless your standard library is really weird, v.erase(&v.front()+idx) should work. Again, did you try it?
And, AFAIK, it is equivalent to &v.front() == v.begin() since vector iterators are pointers.
Cédric
Anyway, from what I can see, really, unless your standard library is really weird, v.erase(&v.front()+idx) should work. Again, did you try it?
And, AFAIK, it is equivalent to &v.front() == v.begin() since vector iterators are pointers.
Cédric
It should work but there appears to be some sort of detail that is missing...you may need to post some of the code.
You can use operator [] with the std::vector too
v.erase(&v[index]);
Although you should check that the index is a valid number
v.erase(&v[index]);
Although you should check that the index is a valid number
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement