First, a couple of things:
1) a vector<bool> is not a vector. Some wise guy thought he could implement C bitfields in C++ and failed at it. All vectors are required to be arrays. Therefore, you can always assign the address of a vector element to a pointer:
- vector<int> v;
-
v.push_back(10);
-
int* ptr = &v[0];
However, this code will not complile for vector<bool>. Refer to Scott Meyers book
Effective STL.
You are supposed to use a
bitset for bool values.
2) You check a bool for true by testing it to be
true and not equal to 1.
bool b = true;
- if (b==true) etc... //OK
-
if(b==1) etc... //not good. May generate warning about coinversion
-
//of 1 ro bool.
3) Your vectors are changing size.
For example, assume the bools are
false true true.
Your loop counter , i, starts at 0. OK.
Nothing is erased. i increments to 1.
Now you erase an element. vector::size is now 2.
i increments to 2.
You exit the loop.
Notice that when vector::size() is 2, the elements of your vectors are 0 and 1.
I suggest you start at vector::begin() and run to vector::end(). You will need to do this until there are no erases. Then you are done.