home *** CD-ROM | disk | FTP | other *** search
/ The C Users' Group Library 1994 August / wc-cdrom-cusersgrouplibrary-1994-08.iso / listings / v_08_11 / 8n11084a < prev    next >
Text File  |  1990-09-18  |  778b  |  35 lines

  1.  
  2. # include <stdio.h>
  3. typedef int Truth;
  4. class File { // Implementation layered on FILE
  5. public:
  6.     File( char *name = "", char *mode = "r")
  7.     {
  8.         if( *name )
  9.             fp = fopen( name, mode);
  10.         else if( *mode == 'r' )
  11.             fp = stdin;
  12.         else
  13.             fp = stdout;
  14.         state = (int)fp;
  15.     }
  16.  
  17.     ~File()           { if( fp) fclose( fp); }
  18.  
  19.     Truth isok()      { return state; }
  20.  
  21.     Truth iseof()     { return feof( fp); }
  22.  
  23.     int get()         { return getc( fp); }
  24.     // unget and peek useful for lexical scanners
  25.     void unget(int c) { (void)ungetc( c, fp); }
  26.  
  27.     int peek()  { int c = get(); unget(c); return c; }
  28.  
  29.     void put( int c)  { putc( c, fp); }
  30. private:
  31.     FILE *fp;
  32.     int state;
  33. };
  34.  
  35.