//: C16:IterStackTemplateTest.cpp // From Thinking in C++, 2nd Edition // Available at http://www.BruceEckel.com // (c) Bruce Eckel 2000 // Copyright notice in Copyright.txt //{L} fibonacci #include "fibonacci.h" #include "IterStackTemplate.h" #include #include #include using namespace std; int main() { StackTemplate is; for(int i = 0; i < 20; i++) is.push(fibonacci(i)); // Traverse with an iterator: cout << "Traverse the whole StackTemplate\n"; StackTemplate::iterator it = is.begin(); while(it != is.end()) cout << it++ << endl; cout << "Traverse a portion\n"; StackTemplate::iterator start = is.begin(), end = is.begin(); start += 5, end += 15; cout << "start = " << start << endl; cout << "end = " << end << endl; while(start != end) cout << start++ << endl; ifstream in("IterStackTemplateTest.cpp"); assure(in, "IterStackTemplateTest.cpp"); string line; StackTemplate strings; while(getline(in, line)) strings.push(line); StackTemplate::iterator sb = strings.begin(), se = strings.end(); while(sb != se) cout << sb++ << endl; } ///:~