472,111 Members | 1,992 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,111 software developers and data experts.

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 1713
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
reply views Thread by leo001 | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.