   list<>
  I''m using the list template in VC++ 6.0.Everything seems to work great, until I start removing items from my list.My (pertinent) code:   list<student> students;list<student>::iterator iterator;//read students into list//open output filestudent temp;while (!students.empty()) {temp = *iterator;output << temp;students.pop_front();}When I run the program, it will run through that loop twice with no problems.  However, the third time, I get an access violation.I''ve tried using the debugger to see what''s going on, and I''m confused.  There are 28 items on the list when the loop begins the first time.  The structure of the list remains intact (just the item at the front keeps changing).  Just before the linetemp = *iterator;the list has the correct item at the front.  But when I watch the internal copy function of the student class, all the internal data for the student is invalid.  If I comment out that line, the program successfully empties the list.  Any idea what''s going on?  Why does the program not pass in the student from the list properly on the third time (it''s a consistant error)? 
  here is how i avoid a read-and-delete routine error with vectors:count backwards!for (int x=list.size()-1; x >= 0; x--) { // count backward to avoid segfault!   cout << list[x]->Whatever();   list.erase( list.begin() + x );   }  [edited by - leiavoia on February 12, 2004 1:01:09 AM];  I don''t see where you actually initialise the iterator to a valid value.Either make it list<student> students;//read students into list//open output filestudent temp;while (!students.empty()) {  temp = front();  output << temp;  students.pop_front();}or list<student> students;//read students into list//open output filestudent temp;while (!students.empty()) {  temp = *begin();  output << temp;  students.pop_front();}You actually don''t even need the iterator with those two methods.Or do this: list<student> students;//read students into list//open output filelist<student>::iterator   it( students.begin() );student temp;while ( it != students.end() ){  temp = *it;  output << temp;  it = students.erase( it );};  I suggest:std::copy(students.begin(), students.end(), std::ostream_iterator<student>(output));students.clear(); 