iterator
-
Can me somebody give an example of an simple iterator (such as STL but simple) ? Thanks. -:KNOX:-
-
Can me somebody give an example of an simple iterator (such as STL but simple) ? Thanks. -:KNOX:-
// Create a list of characters
list charList;
for( int i=0; i < 10; i++ ) {
charList.push_front( i + 65 );
}
// Display the list
list::iterator theIterator;
for( theIterator = charList.begin(); theIterator != charList.end(); theIterator++ ) {
cout << *theIterator;
}SaRath.
"It is your attitude, not your aptitude, that determines your altitude - Zig Ziglar." My Blog | Understanding State Pattern in C++ -
Can me somebody give an example of an simple iterator (such as STL but simple) ? Thanks. -:KNOX:-
An example of what an iterator class looks like or how to use them? If you decide to become a software engineer, you are signing up to have a 1/2" piece of silicon tell you exactly how stupid you really are for 8 hours a day, 5 days a week Zac
-
An example of what an iterator class looks like or how to use them? If you decide to become a software engineer, you are signing up to have a 1/2" piece of silicon tell you exactly how stupid you really are for 8 hours a day, 5 days a week Zac
Yes an class example. -:KNOX:- -- modified at 13:39 Thursday 29th June, 2006
-
Yes an class example. -:KNOX:- -- modified at 13:39 Thursday 29th June, 2006
The most basic example of an iterator is just a pointer:
char buffer[100] = "0"; // create a "container" char* it = buffer; // point to the first element in the buffer for (int i = 0; i < 100; ++i) // iterate through the entire container { *(it++) = 'a'; // set each element to 'a' and increment iterator }
A more indepth example would include writing a basic container class and an iterator class (iterators don't mean much without a corresponding container). If you decide to become a software engineer, you are signing up to have a 1/2" piece of silicon tell you exactly how stupid you really are for 8 hours a day, 5 days a week Zac