I'm working with sets for an exercise, and I got an error message I don't know how to interpret. I'm not too savvy with the technical aspects of programming. I'm a math student, so I have only really focused on the actual programming itself, so certain errors I just don't know how to handle.
I made the set and inserted every integer from 0 to 100 with the endpoints. I then wanted to erase every integer divisible by 2 except 2 itself. Here's the code:
set<int> intSet;
for (int i = 0; i < 101; i++) {
intSet.insert(i);
}
for (set<int>::iterator twoDivIt = intSet.begin(); twoDivIt != intSet.end(); twoDivIt++) {
if (*twoDivIt % 2 == 0) {
if (*twoDivIt == 2) {
continue;
}
else {
intSet.erase(twoDivIt);
}
}
}
for (set<int>::iterator it = intSet.begin(); it != intSet.end(); it++) {
std::cout << *it << "\t";
}
I get a popup window telling me the debuc assertion failed, and that "map/set iterator not incrementable". What have I done wrong?