worditer.h
来自「C++&datastructure书籍源码,以前外教提供现在与大家共享」· C头文件 代码 · 共 50 行
H
50 行
#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 <string>#include <fstream>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
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?