home *** CD-ROM | disk | FTP | other *** search
/ GEMini Atari / GEMini_Atari_CD-ROM_Walnut_Creek_December_1993.iso / files / gnu / g__lib / test0.h < prev    next >
C/C++ Source or Header  |  1993-07-23  |  1KB  |  78 lines

  1. #include <std.h>
  2. #include <stdio.h>
  3. #include <stddef.h>
  4.  
  5. // change the following if ld++ and crt1+.o are in non-standard directories
  6.  
  7. #ifndef LDXX
  8. #define LDXX  "/usr/local/lib/gcc-ld++"
  9. #endif
  10. #ifndef CRT1X
  11. #define CRT1X "/usr/local/lib/gcc-crt1+.o"
  12. #endif
  13.  
  14. class ifile
  15. {
  16.   FILE *fp;
  17.   char *name;
  18.  
  19.  public:
  20.   ifile (char *name)
  21.     {
  22.       this->name = new char[strlen(name) + 1];
  23.       strcpy (this->name, name);
  24.       if ((fp = fopen (name, "r")) == NULL)
  25.     {
  26.       fprintf (stderr, "could not open input file `%s'\n", name);
  27.       exit (1);
  28.     }
  29.     }
  30.  
  31.   ~ifile ()
  32.     {
  33.       fclose (fp);
  34.       if (fp) fprintf (stderr, "closing input file `%s'\n", name);
  35.     }
  36.  
  37.   ifile& operator>> (int &i)
  38.     { fscanf (fp, "%d", &i); return *this; }
  39.   ifile& operator>> (char *p)
  40.     { fscanf (fp, "%s", p); return *this; }
  41. };
  42.  
  43. class ofile
  44. {
  45.   FILE *fp;
  46.   char *name;
  47.  public:
  48.   ofile (char *name)
  49.     {
  50.       this->name = new char[strlen(name) + 1];
  51.       strcpy (this->name, name);
  52.       if ((fp = fopen (name, "w")) == NULL)
  53.     {
  54.       fprintf (stderr, "could not open output file `%s'\n", name);
  55.       exit (1);
  56.     }
  57.     }
  58.  
  59.   ~ofile ()
  60.     {
  61.       fclose (fp);
  62.       if (fp) fprintf (stderr, "closing output file `%s'\n", name);
  63.     }
  64.  
  65.   ofile& operator<< (int i)
  66.     {
  67.       fprintf (fp, "%d", i);
  68.       fflush (fp);
  69.       return *this;
  70.     }
  71.   ofile& operator<< (char *p)
  72.     {
  73.       fprintf (fp, "%s", p);
  74.       fflush (fp);
  75.       return *this;
  76.     }
  77. };
  78.