array ar = { 0, 1, 1, 2, 3, 5, 8, 13, 21, 55, 89 };
vector vec(ar.begin(), ar.end());
auto it = vec.begin();
while (it != vec.end())
{
if (*it % 2)
vec.erase(it);
else
it++;
}
for (auto i : vec)
cout << i;
你每次執行完vec.erase後,都要讓it指向新的vec
把 vec.erase(it);
改為 it = vec.erase(it);