Quiz · Containers and Iterators · lesson 7 of 11
Quiz — erasing in a loop
What is wrong with this loop that removes zeros from v?
#include <vector>
void drop_zeros(std::vector<int>& v) {
for (auto it = v.begin(); it != v.end(); ++it) {
if (*it == 0) {
v.erase(it);
}
}
}