Question: Im having trouble with STl. Im trying to iterate through an STL list of student objects. Im trying to delete objects when I find a matching comparison. However I receive an error when doing the comparison. This is what I have done so far:

```
 string studentName;
                cout<<"Enter name of student to remove";
                cin>>studentName;

                list<Student>::iterator it = studentList.begin();
                while (it != studentList.end()){
                    if(*it== studentName){
                        studentList.erase(it);
                    }
                }

```

I get the error "Invalid operands to binary expression ('value\_type' (aka 'Student') and 'string' (aka 'basic\_string, allocator >'))"
I'm not quite sure how to solve it.
Thank you, any advice is appreciated!

Answer: 
You are comparing an instance of `Student` with an `std::string` which I'm assuming doesn't have a defined `operator==` overloaded function. You can either define this operator or compare `studentName` with the member string variable in `Student` which stores the name of the student. You might consider looking at `std::remove_if` in the algorithms library which you can use to filter out any students which don't have that name.
1. You do not advance the iterator. If you happen to erase the first element, you will crash, otherwise you will get an infinite loop. However, ...
2. There are tons of examples how to iterate lists and erase elements correctly, e.g. here: [Erasing while iterating an std::list](https://stackoverflow.com/questions/16269696/erasing-while-iterating-an-stdlist)