Tuesday, May 5, 2009

C++ list::iterator

So, I found out today that you can't do a "less than" comparison on list iterators.

For instance, if you want to iterate through a list with a for loop, you must do a != comparison, instead of a < comparison usually used in for loops.

for( list::iterator t = myList.begin(); t != myList.end(); t++)
{
// some code
}

This is a sample of proper code to iterate through a list using iterators.

No comments:

Post a Comment