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

  1. /*[]------------------------------------------------------------[]*/
  2. /*|                                                              |*/
  3. /*|     ioststd.cpp                                              |*/
  4. /*|                                                              |*/
  5. /*|     Class iostream                                           |*/
  6. /*|          implements standard streams:                        |*/
  7. /*|              cin                                             |*/
  8. /*|              cout                                            |*/
  9. /*|              cerr                                            |*/
  10. /*|              clog                                            |*/
  11. /*|                                                              |*/
  12. /*[]------------------------------------------------------------[]*/
  13.  
  14. /*
  15.  *      C/C++ Run Time Library - Version 5.0
  16.  *
  17.  *      Copyright (c) 1990, 1992 by Borland International
  18.  *      All Rights Reserved.
  19.  *
  20.  */
  21.  
  22. #include <ioconfig.h>
  23. #include <filesys.h>
  24. #include <fstream.h>
  25.  
  26. // this allows calling a constructor for an existing object
  27. inline void * operator new(size_t, void *p)
  28. {
  29.     return p;
  30. }
  31.  
  32. istream_withassign cin;
  33. ostream_withassign cout;
  34. ostream_withassign cerr;
  35. ostream_withassign clog;
  36.  
  37. streambuf *__stdin_streambuf;
  38. streambuf *__stdout_streambuf;
  39. streambuf *__stderr_streambuf;
  40.  
  41. #pragma warn -use
  42. static void Iostream_init()
  43. {
  44. #pragma startup Iostream_init 16
  45.  
  46.     // initially filebufs for efficiency
  47.     __stdin_streambuf  = new filebuf(F_stdin);
  48.     __stdout_streambuf = new filebuf(F_stdout);
  49.     __stderr_streambuf = new filebuf(F_stderr);
  50.  
  51.     // call constructors for standard streams
  52.     new (&cin)  istream_withassign;
  53.     new (&cout) ostream_withassign;
  54.     new (&cerr) ostream_withassign;
  55.     new (&clog) ostream_withassign;
  56.  
  57.     // attach the standard files to the standard streams
  58.     cin  = __stdin_streambuf;
  59.     cout = __stdout_streambuf;
  60.     clog = __stderr_streambuf;
  61.     cerr = __stderr_streambuf;
  62.  
  63.     // tie cin, cerr, and clog to cout
  64.     cin.tie(&cout);
  65.     clog.tie(&cout);
  66.     cerr.tie(&cout);
  67.  
  68.     // unit-buffer cerr
  69.     cerr.setf(ios::unitbuf);
  70.  
  71.     // if cout is the screen, unit-buffer it too
  72.     if( isatty(1) )
  73.         cout.setf(ios::unitbuf);
  74. }
  75.  
  76. void Iostream_delete()
  77. {
  78. #pragma exit Iostream_delete 16
  79.  
  80.     delete __stdin_streambuf;
  81.     delete __stdout_streambuf;
  82.     delete __stderr_streambuf;
  83. }
  84.