home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 7 / 07.iso / c / c065 / 2.ddi / CLIB2.ZIP / SIOSYNC.CPP < prev    next >
Encoding:
C/C++ Source or Header  |  1990-06-07  |  1.6 KB  |  51 lines

  1. /*-----------------------------------------------------------------------*
  2.  * filename - siosync.cpp
  3.  * sync_with_stdio function
  4.  *-----------------------------------------------------------------------*/
  5.  
  6. /*[]------------------------------------------------------------[]*/
  7. /*|                                                              |*/
  8. /*|     Turbo C++ Run Time Library - Version 1.0                 |*/
  9. /*|                                                              |*/
  10. /*|                                                              |*/
  11. /*|     Copyright (c) 1990 by Borland International              |*/
  12. /*|     All Rights Reserved.                                     |*/
  13. /*|                                                              |*/
  14. /*[]------------------------------------------------------------[]*/
  15.  
  16. #include <stdiostr.h>
  17.  
  18. static short already_done = 0;
  19. static stdiobuf *stdin_siob;
  20. static stdiobuf *stdout_siob;
  21. static stdiobuf *stderr_siob;
  22.  
  23. void ios::sync_with_stdio()
  24. {
  25.     if( already_done )
  26.     return;        // we only do this once!
  27.     already_done = 1;
  28.  
  29.     cin.sync();
  30.     cout.flush();
  31.     clog.flush();
  32.  
  33.     // recover the streambuf space
  34.     cin.rdbuf()->streambuf::~streambuf();
  35.     cout.rdbuf()->streambuf::~streambuf();
  36.     clog.rdbuf()->streambuf::~streambuf();
  37.  
  38.     // make stdiobufs for the stdio files
  39.     stdin_siob = new stdiobuf(stdin);
  40.     stdout_siob = new stdiobuf(stdout);
  41.     stderr_siob = new stdiobuf(stderr);
  42.  
  43.     cin = stdin_siob;
  44.     cout = stdout_siob;
  45.     clog = stderr_siob;
  46.     cerr = stderr_siob;
  47.  
  48.     cout.setf(ios::unitbuf);
  49.     clog.setf(ios::unitbuf);
  50. }
  51.