[[c_tokens]]
 
==== #include <iostream>
#include <fstream>
 
using namespace std;
 
class TokenStream : public ifstream
{
public :
    TokenStream (string fileName) :
        ifstream (fileName)
    {
        nextChar ();
        nextToken ();
    }
 
private:
   char ch;
   void nextChar ();
 
public:
    string token;
    void nextToken ();
};
 
const char eos = 0;
 
void TokenStream::nextChar()
{
    *this >> ch;
    if (! *this)
        ch = eos;
}
 
void TokenStream::nextToken ()
{
   while (ch != eos && ch <= ' ') nextChar ();
 
   token = "";
   if (ch != eos)
   {
       if  (ch >= 'a' && ch <= 'z')
       {
           while (ch >= 'a' && ch <= 'z')
           {
              token = token + ch;
              nextChar ();
           }
       }
       else
       {
          token = string (1, ch);
          nextChar ();
       }
   }
}
 
int main()
{
    TokenStream f ("../stream/abc.txt");
    // TokenStream f ("C:/Users/ZC/Documents/untitled4/abc.txt");
    // TokenStream f ("../untitled4/abc.txt");
 
 
    while (f.token != "")
    {
        cout << f.token << endl;
        f.nextToken ();
    }
 
    return 0;
}
 
// selmy ( psoviti, medvedoviti ) ;
 ====
 
c_tokens.txt · Last modified: 2018/11/26 20:59 by 147.32.8.31
 
Recent changes RSS feed Creative Commons License Donate Powered by PHP Valid XHTML 1.0 Valid CSS Driven by DokuWiki