Help needed with an iterator going out of bounds

This is a discussion on Help needed with an iterator going out of bounds within the C++ Programming forums, part of the General Programming Boards category; I'm writing a program that simulates road traffic, I have a vector of integers inside a structure, which is itself ...

Help needed with an iterator going out of bounds

I'm writing a program that simulates road traffic, I have a vector of integers inside a structure, which is itself the elements of a vector. Everything works fine except the iterator i use to delete elements of the inbedded integer vector seems to be going out bound and then when it trys to delete the element the program crashes.

Where CAR_VEC is [vector < CARS > CAR_VEC;], cars being the struct which PASSD is inside.

The cout's are just so I can check that the integers I want are sensible, which they are. I've tried everything and nailed down the problem to something being deleted that isn't there. Yet I can't see why the iterator is going out of bounds. Is it something to do with the vector being inbedded in a structure, in which case do I need to declare the iterator as part of the larger vector CAR_VEC.

ie [ CAR_VEC[i].vector<int>::iterator STEP;] although I've tried this and it doesn't compile.