home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 7 / 07.iso / c / c082_122 / 9.ddi / IOSTRSR1.ZIP / STSYNC.CPP < prev    next >
Encoding:
C/C++ Source or Header  |  1992-06-10  |  1.6 KB  |  54 lines

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