#ifndef _WORDSTREAMITERATOR_H #define _WORDSTREAMITERATOR_H // Owen Astrachan 7/3/95 // // class WordStreamIterator // // void Open(astring name) // -- initializes iterator to file specified by name // // void First(), void Next(), bool IsDone() // -- "standard" iterating functions (see below) // // usage: call First(), before accessing Current() // call Next() to move to the next word in the stream // call Current() to access the current word // // astring Current() // -- returns current astring (see below) // // words are retrieved from stream until sentinel LAST_WORD is encountered // this sentinel word is read from the stream. Once read, IsDone() // will return true. // // properties: // // if IsDone() == false, then accessing the current word // is a valid operation; access is provided by the member // function Current() // // if IsDone() == true, then accessing the current word is // NOT a valid operation // // #include #include using namespace std; class WordStreamIterator { public: WordStreamIterator(); void Open(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