Can't grok this mysterious code...
Keep it simple:
while (it != v.end()) {
if (++it != v.end() && ++it != v.end())
it = v.erase(it);
}
ArkM
Postaholic
2,001 posts since Jul 2008
Reputation Points: 1,234
Solved Threads: 348
//declare and initialize variables
iterator current = vector.begin
iterator stop = vector.end
int n = 0;
//loop de loop
while(size of vector not equal one)
{
++n;
++current;
if(current equals stop) //reset current to beginning of vector
current = vector.begin
if n equals 3
{
erase current
//reset variables
stop = vector.end
n = 0
}
}
Lerner
Nearly a Posting Maven
2,382 posts since Jul 2005
Reputation Points: 739
Solved Threads: 396
It works fine.
Try to print vector with regular for loop:
for (size_t i = 0; i < v.size(); i++)
cout << v[i] << '\n';
and see what happens.
ArkM
Postaholic
2,001 posts since Jul 2008
Reputation Points: 1,234
Solved Threads: 348