Iterator not incrementable?
So I am trying to write up two versions of a function, that takes in a list of data structure of students(which consists of their name and grades), and filters out all the failing students, and returns me back the list with only passing students.
One method simply erases the student from the list.
Code:
students extract_fails(students& studs){
students fail;
for(students::iterator i = studs.begin(); i != studs.end(); i++){
if(!fgrade(*i)){
fail.push_back(*i);
studs.erase(i);
}
}
return fail;
}
The other pushes all passing students to the beginning and resizes the list to the amount of passing students. The one I just mentioned works, but the one I posted up there doesn't. I get back an error saying the iterator is not incrementable. Why is this? Am I improperly erasing the element from the list?