iterators

This is a discussion on iterators within the C++ Programming forums, part of the General Programming Boards category; Code: for (std::vector<Block>::iterator i = blocks.begin(); i != blocks.end(); ++i) { if ((*i).trigger) blocks.erase(i); } When I erase an iterator ...

  1. #1
    Just because ygfperson's Avatar
    Join Date
    Jan 2002
    Posts
    2,493

    iterators

    Code:
    for (std::vector<Block>::iterator i = blocks.begin(); i != blocks.end(); ++i) {
      if ((*i).trigger)
        blocks.erase(i);
    
    
    }
    When I erase an iterator in a for loop like this one, will it cause a crash? Or will the iterator i automatically go to the next value?

  2. #2
    Just because ygfperson's Avatar
    Join Date
    Jan 2002
    Posts
    2,493
    nm, found the answer: yes

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. vector of strings with iterators.
    By Mario F. in forum C++ Programming
    Replies: 6
    Last Post: 05-31-2006, 01:12 PM
  2. Using reverse iterators in algorithms
    By 0rion in forum C++ Programming
    Replies: 1
    Last Post: 02-27-2006, 03:19 AM
  3. Writing Iterators...
    By DeepBlackMagic in forum C++ Programming
    Replies: 6
    Last Post: 05-29-2003, 10:31 PM
  4. accessing vector elements: iterators are faster?
    By Captain Penguin in forum C++ Programming
    Replies: 1
    Last Post: 11-28-2002, 02:27 PM
  5. Generic Progpammimg Iterators
    By rip1968 in forum C++ Programming
    Replies: 7
    Last Post: 08-06-2002, 11:20 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21