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

  1. // wiostream -- initialize standard wide streams
  2. #include <locale>
  3. #include <fstream>
  4. #include <iostream>
  5. #include <new>
  6. _STD_BEGIN
  7.  
  8.         // OBJECT DECLARATIONS
  9. int _Winit::_Init_cnt = -1;
  10. static wfilebuf wfin(_Noinit);
  11. static wfilebuf wfout(_Noinit);
  12. static wfilebuf wferr(_Noinit);
  13. _CRTIMP2 wistream wcin(_Noinit);
  14. _CRTIMP2 wostream wcout(_Noinit);
  15. _CRTIMP2 wostream wcerr(_Noinit);
  16. _CRTIMP2 wostream wclog(_Noinit);
  17.  
  18. _CRTIMP2 _Winit::_Winit()
  19.     {    // initialize standard wide 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 wide streams
  28.         new (&wfin) wfilebuf(stdin);
  29.         new (&wfout) wfilebuf(stdout);
  30.         new (&wferr) wfilebuf(stderr);
  31.         new (&wcin) wistream(&wfin, true);
  32.         new (&wcout) wostream(&wfout, true);
  33.         wcin.tie(&wcout);
  34.         new (&wcerr) wostream(&wferr, true);
  35.         wcerr.tie(&wcout);
  36.         wcerr.setf(ios_base::unitbuf);
  37.         new (&wclog) wostream(&wferr, true);
  38.         wclog.tie(&wcout);
  39.         }
  40.     }
  41.  
  42. _CRTIMP2 _Winit::~_Winit()
  43.     {    // flush standard wide 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 wide streams
  52.         wcout.flush();
  53.         wcerr.flush();
  54.         wclog.flush();
  55.         }
  56. _STD_END
  57.     }
  58.  
  59. /*
  60.  * Copyright (c) 1994 by P.J. Plauger.  ALL RIGHTS RESERVED. 
  61.  * Consult your license regarding permissions and restrictions.
  62.  */
  63.