469,160 Members | 1,830 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,160 developers. It's quick & easy.

vector::erase

mickey0
142 100+
Hello
I have a vector and an index 'i';
I need something like:
Expand|Select|Wrap|Line Numbers
  1. for (int i = vec.size() - 1 ;i >= 0; i--) {
  2.     if (something(i) ) vec.removeAt(i);
  3. }
  4.  
using c++ standard library; is it possibile from an int gets the iterator?

Thanks,
Aug 10 '08 #1
1 1583
weaknessforcats
9,208 Expert Mod 8TB
Nope.

You have to define a random access interator and set it.

Expand|Select|Wrap|Line Numbers
  1. vector<whatever>::iterator itr;
  2.  
  3. itr = vec.begin();
  4.  
  5. //then:
  6.  
  7. advance(itr);
  8.  
  9. //then
  10.  
  11. vec.erase(itr0;
  12.  
Aug 10 '08 #2

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

1 post views Thread by kaede | last post: by
9 posts views Thread by BCC | last post: by
10 posts views Thread by Alex Vinokur | last post: by
9 posts views Thread by Amadeus W. M. | last post: by
3 posts views Thread by ma740988 | last post: by
3 posts views Thread by subramanian100in | last post: by
1 post views Thread by Mortomer39 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.