home *** CD-ROM | disk | FTP | other *** search
/ Tricks of the Windows Gam…ming Gurus (2nd Edition) / Disc2.iso / vc98 / crt / src / iostream.cpp < prev    next >
C/C++ Source or Header  |  1998-06-16  |  2KB  |  70 lines

  1. // iostream -- ios::Init members, initialize standard streams
  2. #include <locale>
  3. #include <fstream>
  4. #include <istream>    /* NOT <iostream> */
  5. #include <new>
  6. _STD_BEGIN
  7.  
  8.         // OBJECT DECLARATIONS
  9. int ios_base::Init::_Init_cnt = -1;
  10. static filebuf fin(_Noinit);
  11. static filebuf fout(_Noinit);
  12. _CRTIMP2 istream cin(_Noinit);
  13. _CRTIMP2 ostream cout(_Noinit);
  14. static filebuf ferr(_Noinit);
  15. _CRTIMP2 ostream cerr(_Noinit);
  16. _CRTIMP2 ostream clog(_Noinit);
  17.  
  18. _CRTIMP2 ios_base::Init::Init()
  19.     {    // initialize standard streams first time
  20.     bool doinit;
  21.         {_Lockit _Lk;
  22.         if (0 <= _Init_cnt)
  23.             ++_Init_cnt, doinit = false;
  24.         else
  25.             _Init_cnt = 1, doinit = true; }
  26.     if (doinit)
  27.         {    // initialize standard streams
  28.         new (&fin) filebuf(stdin);
  29.         new (&fout) filebuf(stdout);
  30.         new (&cin) istream(&fin, true);
  31.         new (&cout) ostream(&fout, true);
  32.         cin.tie(&cout);
  33.         new (&ferr) filebuf(stderr);
  34.         new (&cerr) ostream(&ferr, true);
  35.         cerr.tie(&cout);
  36.         cerr.setf(ios_base::unitbuf);
  37.         new (&clog) ostream(&ferr, true);
  38.         clog.tie(&cout);
  39.         }
  40.     }
  41.  
  42. _CRTIMP2 ios_base::Init::~Init()
  43.     {    // flush standard streams last time
  44.     bool doflush;
  45.         {_Lockit _Lk;
  46.         if (--_Init_cnt == 0)
  47.             doflush = true;
  48.         else
  49.             doflush = false; }
  50.     if (doflush)
  51.         {    // flush standard streams
  52.         cout.flush();
  53.         cerr.flush();
  54.         clog.flush();
  55.         }
  56. _STD_END
  57.     }
  58.  
  59. const char _PJP_CPP_Copyright[] =
  60.     "Portions of this work are derived"
  61.     " from 'The Draft Standard C++ Library',\n"
  62.     "copyright (c) 1994-1995 by P.J. Plauger,"
  63.     " published by Prentice-Hall,\n"
  64.     "and are used with permission.";
  65.  
  66. /*
  67.  * Copyright (c) 1994 by P.J. Plauger.  ALL RIGHTS RESERVED. 
  68.  * Consult your license regarding permissions and restrictions.
  69.  */
  70.