i've never before used STL. I'm fiddling with a part of a program that is supposed to pop one item off a list, and push it onto the back of another list:
background stuff:
there is just one item in jobqueue.
(please excuse the massive amounts of debugging/trace stuff
)
and this is my output for that code segment:
and then i get an access violation. the debugger shows the access violation being in the beginning of the loop again, even though the iterator goes beyond the end of the list. so then i'm trying to access variables inside a nonexistant object past the end of the container.
or at least, so it seems like to me.
what am i doing wrong with my iterators, that is making the loop go through too many times?
background stuff:
Code:
list<Pcb>::iterator it;
list<Pcb> readyqueue;
list<Pcb> jobqueue;
(please excuse the massive amounts of debugging/trace stuff
Code:
while(it != jobqueue.end()){
cout<<"Examining process "<<it->jobNum<<endl;
cout<<"Entering if: it->state=="<<it->state<<endl;
cout.flush();
if(it->state==STATE_READY){
readyqueue.push_back(*it); // queue up
cout<<"\tProcess "<<it->jobNum<<" pushed onto readyqueue.\n";
cout<<"\treadyqueue tail has jobNum = "<<readyqueue.back().jobNum<<endl;
cout.flush();
cout<<"\tProcess "<<it->jobNum<<" being removed from jobqueue.\n";
cout.flush();
jobqueue.erase(it); // remove from jobqueue
}
cout<<"Outside of if\n";
cout.flush();
// getch();
it++;
}
cout<<"All ready processes have been moved from job queue to ready queue.\n";
cout.flush();
and this is my output for that code segment:
Code:
Examining process 1
Entering if: it->state==3
Process 1 pushed onto readyqueue.
readyqueue tail has jobNum = 1
Process 1 being removed from jobqueue.
Outside of if
or at least, so it seems like to me.
what am i doing wrong with my iterators, that is making the loop go through too many times?