#ifndef _WORDSTREAMITERATOR_H #define _WORDSTREAMITERATOR_H // Owen Astrachan 7/3/95, modified 4/9/99 // // class WordStreamIterator // // void Open(string name) // -- initializes iterator to file specified by name // // void Init(), void Next(), bool HasMore() // -- "standard" iterating functions (see below) // // usage: call Init(), before accessing Current() // call Next() to move to the next word in the stream // call Current() to access the current word // call HasMore() to determine if Current() is valid // // string Current() // -- returns current string (see below) // // WordStreamIterator iter; // iter.Open("testfile.dat"); // for(iter.Init(); iter.HasMore(); iter.Next()) // cout << iter.Current() << endl; // // #include #include using namespace std; class WordStreamIterator { public: WordStreamIterator(); void Open(const string & name); // bind stream to specific text file void Init(); // initialize iterator string Current(); // returns current word bool HasMore(); // true if more words void Next(); // advance to next word private: string myWord; // the current word bool myMore; // true if more words ifstream myInput; // the stream to read from }; #endif