home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 7 / 07.iso / c / c021 / 7.img / INCLUDE.ZIP / IOSTREAM.H < prev    next >
Encoding:
C/C++ Source or Header  |  1990-05-04  |  24.7 KB  |  705 lines

  1. /* iostream.h -- basic stream I/O declarations
  2.  
  3.     Copyright (c) 1990 by Borland International    
  4.     All rights reserved.
  5.  
  6.     There are some inline functions here which generate a LOT of code
  7.     (as much as 300 bytes), but are available inline because AT&T did
  8.     it that way.  We have also made them true functions in the library
  9.     and conditionally deleted the inline code from this header.
  10.     
  11.     If you really want these big functions to be inline, #define the
  12.     macro name _BIG_INLINE_ before including this header.
  13.  
  14.     Programs will compile and link correctly even if some modules are
  15.     compiled with _BIG_INLINE_ and some are not.
  16. */
  17.  
  18. #ifndef __IOSTREAM_H
  19. #define __IOSTREAM_H
  20.  
  21. #include <mem.h>    // to get memcpy and NULL
  22.  
  23. #if __STDC__
  24. #define _Cdecl
  25. #else
  26. #define _Cdecl    cdecl
  27. #endif
  28.  
  29. // Definition of EOF must match the one in <stdio.h>
  30. #define EOF (-1)
  31.  
  32. // extract a char from int i, ensuring that zapeof(EOF) != EOF
  33. #define    zapeof(i) ((unsigned char)(i))
  34.  
  35. typedef long streampos;
  36. typedef long streamoff;
  37.  
  38. class streambuf;
  39. class ostream;
  40.  
  41.  
  42. class ios {
  43. public:
  44.     // stream status bits
  45.     enum io_state    {
  46.         goodbit     = 0x00,    // no bit set: all is ok
  47.         eofbit     = 0x01,    // at end of file
  48.         failbit     = 0x02,    // last I/O operation failed
  49.         badbit     = 0x04,    // invalid operation attempted
  50.         hardfail = 0x80        // unrecoverable error
  51.         };
  52.  
  53.     // stream operation mode
  54.     enum open_mode    {
  55.         in     = 0x01,        // open for reading
  56.         out     = 0x02,        // open for writing
  57.         ate     = 0x04,        // seek to eof upon original open
  58.         app     = 0x08,        // append mode: all additions at eof
  59.         trunc     = 0x10,    // truncate file if already exists
  60.         nocreate = 0x20,    // open fails if file doesn't exist
  61.         noreplace= 0x40,    // open fails if file already exists
  62.         binary     = 0x80        // binary (not text) file
  63.         };
  64.  
  65.     // stream seek direction
  66.     enum seek_dir { beg=0, cur=1, end=2 };
  67.  
  68.     // formatting flags
  69.     enum    {
  70.         skipws      = 0x0001,    // skip whitespace on input
  71.         left      = 0x0002,    // left-adjust output
  72.         right      = 0x0004,    // right-adjust output
  73.         internal  = 0x0008,    // padding after sign or base indicator
  74.         dec      = 0x0010,        // decimal conversion
  75.         oct      = 0x0020,        // octal conversion
  76.         hex      = 0x0040,        // hexidecimal conversion
  77.         showbase  = 0x0080,    // use base indicator on output
  78.         showpoint = 0x0100,    // force decimal point (floating output)
  79.         uppercase = 0x0200,    // upper-case hex output
  80.         showpos      = 0x0400,    // add '+' to positive integers
  81.         scientific= 0x0800,    // use 1.2345E2 floating notation
  82.         fixed      = 0x1000,    // use 123.45 floating notation
  83.         unitbuf      = 0x2000,    // flush all streams after insertion
  84.         stdio      = 0x4000    // flush stdout, stderr after insertion
  85.         };
  86.  
  87.     // constants for second parameter of seft()
  88. static    const long basefield;        // dec | oct | hex
  89. static    const long adjustfield;        // left | right | internal
  90. static    const long floatfield;        // scientific | fixed
  91.  
  92.     // constructor, destructor
  93.         _Cdecl ios(streambuf*);
  94. virtual    _Cdecl ~ios();
  95.  
  96.     // for reading/setting/clearing format flags
  97.     long    _Cdecl flags();
  98.     long    _Cdecl flags(long);
  99.     long    _Cdecl setf(long _setbits, long _field);
  100.     long    _Cdecl setf(long);
  101.     long    _Cdecl unsetf(long);
  102.  
  103.     // reading/setting field width
  104.     int        _Cdecl width();
  105.     int        _Cdecl width(int);
  106.  
  107.     // reading/setting padding character
  108.     char    _Cdecl fill();
  109.     char    _Cdecl fill(char);
  110.  
  111.     // reading/setting digits of floating precision
  112.     int        _Cdecl precision(int);
  113.     int        _Cdecl precision();
  114.  
  115.     // reading/setting ostream tied to this stream
  116.     ostream* _Cdecl tie(ostream*);
  117.     ostream* _Cdecl tie();
  118.  
  119.     // find out about current stream state
  120.     int        _Cdecl rdstate();        // return the stream state
  121.     int        _Cdecl eof();            // non-zero on end of file
  122.     int        _Cdecl fail();            // non-zero if an operation failed
  123.     int        _Cdecl bad();            // non-zero if error occurred
  124.     int        _Cdecl good();            // non-zero if no state bits set
  125.     void    _Cdecl clear(int = 0);    // set the stream state
  126.             _Cdecl operator void* ();    // zero if state failed
  127.     int        _Cdecl operator! ();    // non-zero if state failed
  128.  
  129.     streambuf* _Cdecl rdbuf();        // get the assigned streambuf
  130.  
  131.     // for declaring additional flag bits and user words
  132. static long    _Cdecl bitalloc();    // acquire a new flag bit, value returned
  133. static int    _Cdecl xalloc();    // acquire a new user word, index returned
  134.     long  & _Cdecl iword(int);    // return the nth user word as an int
  135.     void* & _Cdecl pword(int);    // return the nth user word as a pointer
  136.  
  137. static void    _Cdecl sync_with_stdio();
  138.  
  139.     // obsolete, for streams 1.2 compatibility
  140.     int        _Cdecl skip(int);
  141.  
  142. protected:
  143.     // additional state flags for ispecial and ospecial
  144.     enum { skipping = 0x100, tied = 0x200 };
  145.  
  146.     streambuf* bp;            // the associated streambuf
  147.     ostream* x_tie;            // the tied ostream, if any
  148.     int        state;            // status bits
  149.     int        ispecial;        // istream status bits    ***
  150.     int        ospecial;        // ostream status bits    ***
  151.     long     x_flags;        // formatting flag bits
  152.     int        x_precision;    // floating-point precision on output
  153.     int     x_width;        // field width on output
  154.     int        x_fill;            // padding character on output
  155.     int        isfx_special;    // unused        ***
  156.     int        osfx_special;    // unused        ***
  157.     int        delbuf;            // unused        ***
  158.     int        assign_private;    // unused        ***
  159. /*
  160.  * The data members marked with *** above are not documented in the AT&T
  161.  * release of streams, so we cannot guarantee compatibility with any
  162.  * other streams release in the use or values of these data members.
  163.  * If you can document any expected behavior of these data members, we
  164.  * will try to adjust our implementation accordingly.
  165.  */
  166.  
  167.             _Cdecl ios();        // null constructor, does not initialize
  168.             
  169.     void    _Cdecl init(streambuf*);    // the actual initialization
  170.  
  171.     void    _Cdecl setstate(int);        // set all status bits
  172.  
  173. static    void _Cdecl (*stdioflush)();
  174.  
  175. private:
  176.     // for extra flag bits and user words
  177. static    long    nextbit;
  178. static    int    usercount;
  179.     union ios_user_union *userwords;
  180.     int        nwords;
  181.     void    _Cdecl usersize(int);
  182.  
  183.     // these declarations prevent automatic copying of an ios
  184.             _Cdecl ios(ios&);            // declared but not defined
  185.     void    _Cdecl operator= (ios&);    // declared but not defined
  186.  
  187. };
  188. inline streambuf* _Cdecl ios::rdbuf() { return bp; }
  189. inline ostream* _Cdecl ios::tie() { return x_tie; }    
  190. inline char        _Cdecl ios::fill() { return x_fill; }
  191. inline int        _Cdecl ios::precision() { return x_precision; }
  192. inline int        _Cdecl ios::rdstate() { return state; }
  193. inline int        _Cdecl ios::eof() { return state & eofbit; }
  194. inline int        _Cdecl ios::fail() { return state & (failbit | badbit | hardfail); }
  195. inline int        _Cdecl ios::bad() { return state & (badbit | hardfail); }
  196. inline int        _Cdecl ios::good() { return state == 0; }
  197. inline long        _Cdecl ios::flags() { return x_flags; }
  198. inline int        _Cdecl ios::width() { return x_width; }
  199. inline int        _Cdecl ios::width(int _w) { int _i = x_width; x_width = _w; return _i; }
  200. inline char        _Cdecl ios::fill(char _c) { char _x = x_fill; x_fill = _c; return _x; }
  201. inline int        _Cdecl ios::precision(int _p) {
  202.                         int _x = x_precision; x_precision = _p; return _x;
  203.                         }
  204. inline            _Cdecl ios::operator void* () { return fail() ? 0 : this; }
  205. inline int        _Cdecl ios::operator! () { return fail(); }
  206.  
  207.  
  208. class streambuf {
  209. public:
  210.     // constructors and destructors
  211.         _Cdecl streambuf();                // make empty streambuf
  212.         _Cdecl streambuf(char*, int);    // make streambuf with given char array
  213. virtual    _Cdecl ~streambuf();
  214.  
  215.     // use the provided char array for the buffer if possible
  216. virtual streambuf* _Cdecl setbuf(  signed char*, int);
  217.     // WARNING:  this function is not virtual; do not override
  218.        streambuf*  _Cdecl setbuf(unsigned char*, int);
  219.  
  220.     // obsolete, for streams 1.2 compatibility
  221.     streambuf*  _Cdecl setbuf(char*, int, int);
  222.  
  223.     // getting (extracting) characters
  224.     int        _Cdecl sgetc();            // peek at next char
  225.     int        _Cdecl snextc();        // advance to and return next char
  226.     int        _Cdecl sbumpc();        // return current char and advance
  227.     void    _Cdecl stossc();        // advance to next character
  228.     int        _Cdecl sgetn(char*, int);    // get next n chars
  229. virtual int    _Cdecl do_sgetn(char*, int);    // implementation of sgetn
  230. virtual int    _Cdecl underflow();        // fill empty buffer
  231.     int        _Cdecl sputbackc(char);    // return char to input
  232. virtual int    _Cdecl pbackfail(int);    // implementation of sputbackc
  233.     int        _Cdecl in_avail();        // number of avail chars in buffer
  234.  
  235.     // putting (inserting) characters
  236.     int        _Cdecl sputc(int);            // put one char
  237.     int        _Cdecl sputn(const char*, int); // put n chars from string
  238. virtual int    _Cdecl do_sputn(const char* s, int n); // implementation of sputn
  239. virtual int    _Cdecl overflow(int = EOF);    // flush buffer and make more room
  240.     int        _Cdecl out_waiting();        // number of unflushed chars
  241.  
  242.     // moving around in stream
  243. virtual streampos _Cdecl seekoff(streamoff, seek_dir, int = (ios::in | ios::out));
  244. virtual streampos _Cdecl seekpos(streampos, int = (ios::in | ios::out));
  245. virtual int    _Cdecl sync();
  246.  
  247.     void    _Cdecl dbp();        // for debugging streambuf implementations
  248.  
  249. protected:
  250.     char*    _Cdecl base();        // return start of buffer area
  251.     char*    _Cdecl ebuf();        // return end+1 of buffer area
  252.     int        _Cdecl blen();        // return length of buffer area
  253.     char*    _Cdecl pbase();        // return start of put area
  254.     char*    _Cdecl pptr();        // return next location in put area
  255.     char*    _Cdecl epptr();        // return end+1 of put area
  256.     char*    _Cdecl eback();        // return base of putback section of get area
  257.     char*    _Cdecl gptr();        // return next location in get area
  258.     char*    _Cdecl egptr();        // return end+1 of get area
  259.     void    _Cdecl setp(char*, char*);        // initialize the put pointers
  260.     void    _Cdecl setg(char*, char*, char*);    // initialize the get pointers
  261.     void    _Cdecl pbump(int);    // advance the put pointer
  262.     void    _Cdecl gbump(int);    // advance the get pointer
  263.     void    _Cdecl setb(char*, char*, int = 0 );    // set the buffer area
  264.     void    _Cdecl unbuffered(int);// set the buffering state
  265.     int        _Cdecl unbuffered();    // non-zero if not buffered
  266.     int        _Cdecl allocate();    // set up a buffer area
  267. virtual int    _Cdecl doallocate();    // implementation of allocate
  268.  
  269. private:
  270.     short    alloc_;        // non-zero if buffer should be deleted
  271.     short    unbuf_;        // non-zero if unbuffered
  272.     char*    base_;        // start of buffer area
  273.     char*    ebuf_;        // end+1 of buffer area
  274.     char*    pbase_;        // start of put area
  275.     char*    pptr_;        // next put location
  276.     char*    epptr_;        // end+1 of put area
  277.     char*    eback_;        // base of putback section of get area
  278.     char*    gptr_;        // next get location
  279.     char*    egptr_;        // end+1 of get area
  280.  
  281.     int        _Cdecl do_snextc();    // implementation of snextc
  282.  
  283.     // these declarations prevent copying of a streambuf
  284.             _Cdecl streambuf(streambuf&);    // declared but not defined
  285.     void    _Cdecl operator= (streambuf&);    // declared but not defined
  286. };
  287. inline char* _Cdecl streambuf::base() { return base_; }
  288. inline char* _Cdecl streambuf::pbase() { return pbase_; }
  289. inline char* _Cdecl streambuf::pptr() { return pptr_; }
  290. inline char* _Cdecl streambuf::epptr() { return epptr_; }
  291. inline char* _Cdecl streambuf::gptr() { return gptr_; }
  292. inline char* _Cdecl streambuf::egptr()    { return egptr_; }
  293. inline char* _Cdecl streambuf::eback()    { return eback_; }
  294. inline char* _Cdecl streambuf::ebuf()    { return ebuf_; }
  295. inline int     _Cdecl streambuf::unbuffered() { return unbuf_; }
  296. inline int     _Cdecl streambuf::blen() { return (int)(ebuf_ - base_);}
  297. inline streambuf* _Cdecl streambuf::setbuf(unsigned char* _p, int _len) {
  298.             // call the virtual function
  299.             return setbuf((signed char*)_p, _len);
  300.             }
  301. inline void    _Cdecl streambuf::pbump(int _n) { pptr_ += _n; }
  302. inline void    _Cdecl streambuf::gbump(int _n) { gptr_ += _n; }
  303. inline void    _Cdecl streambuf::unbuffered(int _unb) { unbuf_ = (_unb != 0); }
  304. inline int    _Cdecl streambuf::in_avail() {
  305.                 return (egptr_ > gptr_) ? (int)(egptr_ - gptr_) : 0;
  306.                 }
  307. inline int    _Cdecl streambuf::out_waiting() { return pptr_ ? (int)(pptr_ - pbase_) : 0; }
  308. inline int    _Cdecl streambuf::allocate() {
  309.                 return (base_ || unbuf_) ? 0 : doallocate();
  310.                 }
  311. inline int    _Cdecl streambuf::sgetc() {
  312.                 return (gptr_ >= egptr_) ? underflow() :
  313.                    (unsigned char)(*gptr_);
  314.                 }
  315. inline int    _Cdecl streambuf::snextc() {
  316.                 return (! gptr_ || (++gptr_ >= egptr_)) ?
  317.                     do_snextc() :
  318.                     (unsigned char)(*gptr_);
  319.                 }
  320. inline int    _Cdecl streambuf::sbumpc() {
  321.                 return (gptr_ >= egptr_ && underflow() == EOF) ?
  322.                     EOF :
  323.                     (unsigned char)(*gptr_++);
  324.                 }
  325. inline void    _Cdecl streambuf::stossc() {
  326.                 if( gptr_ >= egptr_ ) underflow();
  327.                 else ++gptr_;
  328.                 }
  329. inline int    _Cdecl streambuf::sputbackc(char _c) {
  330.                 return (gptr_ > eback_) ?
  331.                     (unsigned char)(*--gptr_ = _c) :
  332.                     pbackfail(_c);
  333.                 }
  334. inline int    _Cdecl streambuf::sputc(int _c) {
  335.                 return (pptr_ >= epptr_) ?
  336.                     overflow((unsigned char)_c) :
  337.                     (unsigned char)(*pptr_++ = _c);
  338.                 }
  339. #ifdef _BIG_INLINE_
  340. inline int    _Cdecl streambuf::sputn(const char* _s, int _n) {
  341.                 if( _n <= (epptr_ - pptr_) ) {
  342.                     memcpy(pptr_, _s, _n);
  343.                     pbump(_n);
  344.                     return _n;
  345.                 }
  346.                 return do_sputn(_s, _n);
  347.                 }
  348. inline int    _Cdecl streambuf::sgetn(char* _s, int _n) {
  349.                 if( _n <= (egptr_ - gptr_) ) {
  350.                     memcpy(_s, gptr_, _n);
  351.                     gbump(_n);
  352.                     return _n;
  353.                 }
  354.                 return do_sgetn(_s, _n);
  355.                 }
  356. #endif
  357.  
  358.  
  359. class istream : virtual public ios {
  360. public:
  361.     // constructor and destructor
  362.         _Cdecl istream(streambuf*);
  363. virtual    _Cdecl ~istream();
  364.  
  365.     // Obsolete constructors, for streams 1.2 compatibility
  366.         // obsolete: set skip via format, tie via tie() function
  367.         _Cdecl istream(streambuf*, int _sk, ostream* _t=0);
  368.         // obsolete: use strstream
  369.         _Cdecl istream(int _sz, char*, int _sk=1);
  370.         // obsolete: use fstream
  371.         _Cdecl istream(int _fd, int _sk=1, ostream* _t=0);
  372.  
  373.     int    _Cdecl ipfx(int = 0);        // input prefix function
  374.     int    _Cdecl ipfx0();        // same as ipfx(0)
  375.     int    _Cdecl ipfx1();        // same as ipfx(1)
  376.     void _Cdecl isfx()        { }    // unused input suffix function
  377.  
  378.     // set/read the get pointer's position
  379.     istream& _Cdecl seekg(streampos);
  380.     istream& _Cdecl seekg(streamoff, seek_dir);
  381.        streampos _Cdecl tellg();
  382.  
  383.     int    _Cdecl sync();
  384.  
  385.     /*
  386.      * Unformatted extraction operations
  387.      */
  388.     // extract characters into an array
  389.     istream& _Cdecl get(  signed char*, int, char = '\n');
  390.     istream& _Cdecl get(unsigned char*, int, char = '\n');
  391.     istream& _Cdecl read(  signed char*, int);
  392.     istream& _Cdecl read(unsigned char*, int);
  393.  
  394.     // extract characters into an array up to termination char
  395.     istream& _Cdecl getline(  signed char*, int, char = '\n');
  396.     istream& _Cdecl getline(unsigned char*, int, char = '\n');
  397.  
  398.     // extract characters into a streambuf up to termination char
  399.     istream& _Cdecl get(streambuf&, char = '\n');
  400.  
  401.     // extract a single character
  402.     istream& _Cdecl get(unsigned char&);
  403.     istream& _Cdecl get(  signed char&);
  404.     int      _Cdecl get();
  405.                      
  406.     int         _Cdecl peek();        // return next char without extraction
  407.     int         _Cdecl gcount();    // number of unformatted chars last extracted
  408.     istream& _Cdecl putback(char);    // push back char into input
  409.  
  410.     // extract and discard chars but stop at delim
  411.     istream& _Cdecl ignore(int = 1, int = EOF);
  412.  
  413.     /*
  414.      * Formatted extraction operations
  415.      */
  416.     istream& _Cdecl operator>> (istream& (*_f)(istream&));
  417.     istream& _Cdecl operator>> (ios& (*_f)(ios&) );
  418.     istream& _Cdecl operator>> (  signed char*);
  419.     istream& _Cdecl operator>> (unsigned char*);
  420.     istream& _Cdecl operator>> (unsigned char&);
  421.     istream& _Cdecl operator>> (  signed char&);
  422.     istream& _Cdecl operator>> (short&);
  423.     istream& _Cdecl operator>> (int&);
  424.     istream& _Cdecl operator>> (long&);
  425.     istream& _Cdecl operator>> (unsigned short&);
  426.     istream& _Cdecl operator>> (unsigned int&);
  427.     istream& _Cdecl operator>> (unsigned long&);
  428.     istream& _Cdecl operator>> (float&);
  429.     istream& _Cdecl operator>> (double&);
  430.     istream& _Cdecl operator>> (long double&);
  431.  
  432.     // extract from this istream, insert into streambuf
  433.     istream& _Cdecl operator>> (streambuf*);
  434.  
  435. protected:
  436.             _Cdecl istream();
  437.     int        _Cdecl do_ipfx(int);    // implementation of ipfx
  438.     void    _Cdecl eatwhite();        // extract consecutive whitespace
  439.  
  440. private:
  441.     int    gcount_;    // chars extracted by last unformatted operation
  442.     signed char _Cdecl do_get();    // implementation of get
  443. };
  444. inline int    _Cdecl istream::gcount() { return gcount_; }
  445. inline int    _Cdecl istream::ipfx(int _need) {
  446.                 if( _need ? (ispecial & ~skipping) : ispecial )
  447.                     return do_ipfx(_need);
  448.                 return 1;
  449.                 }
  450. inline int    _Cdecl istream::ipfx0() { return ispecial ? do_ipfx(0) : 1; }
  451. inline int    _Cdecl istream::ipfx1() {
  452.                 return (ispecial & ~skipping) ? do_ipfx(1) : 1;
  453.                 }
  454. #ifdef _BIG_INLINE_
  455. inline istream& _Cdecl istream::operator>> (unsigned char& _c) {
  456.                 if( ipfx0() )
  457.                     _c = bp->in_avail() ? bp->sbumpc() : do_get();
  458.                 return *this;
  459.                 }
  460. inline istream& _Cdecl istream::operator>> (signed char& _c) {
  461.                 if( ipfx0() )
  462.                     _c = bp->in_avail() ? bp->sbumpc() : do_get();
  463.                 return *this;
  464.                 }
  465. #endif
  466. inline istream&    _Cdecl istream::operator>> (unsigned char* _p) {
  467.                 return *this >> (signed char *)_p;
  468.                 }
  469. inline istream&    _Cdecl istream::get(unsigned char* _p, int _l, char _t) {
  470.                 return get((signed char*)_p, _l, _t);
  471.                 }
  472. inline istream&    _Cdecl istream::read(unsigned char* _p, int _l) {
  473.                 return read((signed char*)_p, _l);
  474.                 }
  475. inline istream&    _Cdecl istream::getline(unsigned char* _p, int _l, char _t) {
  476.                 return getline((signed char*) _p, _l, _t);
  477.                 }
  478. inline int        _Cdecl istream::sync() { return bp->sync(); }
  479. inline istream& _Cdecl istream::operator>> (istream& (*_f) (istream&)) {
  480.                 return (*_f)(*this);
  481.                 }
  482. #ifdef _BIG_INLINE_
  483. inline istream& _Cdecl istream::get(unsigned char& _c) {
  484.                 if( ipfx1() )
  485.                     if( bp->in_avail() ) {
  486.                         gcount_ = 1;
  487.                         _c = bp->sbumpc();
  488.                     }
  489.                 else _c = do_get();
  490.                 return *this;
  491.                 }
  492. inline istream& _Cdecl istream::get(signed char& _c) {
  493.                 if( ipfx1() )
  494.                     if( bp->in_avail()) {
  495.                         gcount_ = 1;
  496.                         _c = bp->sbumpc();
  497.                     }
  498.                 else _c = do_get();
  499.                 return *this;
  500.                 }
  501. inline int         _Cdecl istream::get() {
  502.                 if( ipfx1() ) {
  503.                     int _c = bp->sbumpc();
  504.                     if( _c == EOF ) setstate(eofbit);
  505.                     else gcount_ = 1;
  506.                     return _c;
  507.                 }
  508.                 else return EOF;
  509.                 }
  510. #endif
  511. inline int    _Cdecl istream::peek() { return ipfx1() ? bp->sgetc() : EOF; }
  512.  
  513.  
  514. class ostream : virtual public ios {
  515. public:
  516.     // constructors and destructor
  517.         _Cdecl ostream(streambuf*);
  518. virtual    _Cdecl ~ostream();
  519.     // Obsolete constructors, for streams 1.2 compatibility
  520.         _Cdecl ostream(int _fd); // obsolete, use fstream
  521.         _Cdecl ostream(int _sz, char*); // obsolete, use strstream
  522.  
  523.     int    _Cdecl opfx();        // output prefix function
  524.     void _Cdecl osfx();        // output suffix function
  525.     ostream& _Cdecl flush();
  526.  
  527.     // set/read the put pointer's position
  528.     ostream& _Cdecl seekp(streampos);
  529.     ostream& _Cdecl seekp(streamoff, seek_dir);
  530.      streampos _Cdecl tellp();
  531.  
  532.     /*
  533.      * Unformatted insertion operations
  534.      */
  535.     ostream& _Cdecl put(char);    // insert the character
  536.     ostream& _Cdecl write(const   signed char*, int); // insert the string
  537.     ostream& _Cdecl write(const unsigned char*, int); // insert the string
  538.  
  539.     /*
  540.      * Formatted insertion operations
  541.      */
  542.     // insert the character
  543.     ostream& _Cdecl operator<< (  signed char);
  544.     ostream& _Cdecl operator<< (unsigned char);
  545.  
  546.     // for the following, insert character representation of numeric value
  547.     ostream& _Cdecl operator<< (short);
  548.     ostream& _Cdecl operator<< (unsigned short);
  549.     ostream& _Cdecl operator<< (int);
  550.     ostream& _Cdecl operator<< (unsigned int);
  551.     ostream& _Cdecl operator<< (long);
  552.     ostream& _Cdecl operator<< (unsigned long);
  553.     ostream& _Cdecl operator<< (float);
  554.     ostream& _Cdecl operator<< (double);
  555.     ostream& _Cdecl operator<< (long double);
  556.  
  557.     // insert the null-terminated string
  558.     ostream& _Cdecl operator<< (const   signed char*);
  559.     ostream& _Cdecl operator<< (const unsigned char*);
  560.  
  561.     // insert character representation of the value of the pointer
  562.     ostream& _Cdecl operator<< (void*);
  563.  
  564.     // extract from streambuf, insert into this ostream
  565.     ostream& _Cdecl operator<< (streambuf*);
  566.  
  567.     // manipulators
  568.     ostream& _Cdecl operator<< (ostream& (*_f)(ostream&));
  569.     ostream& _Cdecl operator<< (ios& (*_f)(ios&));
  570.  
  571. protected:
  572.     int        _Cdecl do_opfx();    // implementation of opfx
  573.     void    _Cdecl do_osfx();    // implementation of osfx
  574.             _Cdecl ostream();
  575.  
  576. private:
  577.     void    _Cdecl outstr(const char*, const char*);
  578. };
  579. inline int    _Cdecl ostream::opfx() { return ospecial ? do_opfx() : 1; }
  580. inline void    _Cdecl ostream::osfx() { if( x_flags & (stdio | unitbuf) ) do_osfx(); }
  581. #ifdef _BIG_INLINE_
  582. inline ostream& _Cdecl ostream::operator<< (signed char _c) {
  583.                 if( opfx() )
  584.                     if( bp->sputc(_c) == EOF ) setstate(badbit);
  585.                         osfx();
  586.                 return *this;
  587.                 }
  588. #endif
  589. inline ostream& _Cdecl ostream::operator<< (unsigned char _c) {
  590.                 return *this << (signed char)_c;
  591.                 }
  592. inline ostream& _Cdecl ostream::operator<< (const signed char* _s) {
  593.                 outstr((const char*)_s, (const char*)0);
  594.                 return *this;
  595.                 }
  596. inline ostream& _Cdecl ostream::operator<< (const unsigned char* _s) {
  597.                 outstr((const char*)_s, (const char*)0);
  598.                 return *this;
  599.                 }
  600. inline ostream& _Cdecl ostream::operator<< (short _i) { return *this << (long) _i; }
  601. inline ostream& _Cdecl ostream::operator<< (unsigned short _i) {
  602.                 return *this << (unsigned long) _i;
  603.                 }
  604. inline ostream& _Cdecl ostream::operator<< (int _i) { return *this << (long) _i; }
  605. inline ostream& _Cdecl ostream::operator<< (unsigned int _i) {
  606.                 return *this << (unsigned long) _i;
  607.                 }
  608. inline ostream& _Cdecl ostream::operator<< (float _f) { return *this << (long double) _f; }
  609. inline ostream& _Cdecl ostream::operator<< (double _d) { return *this << (long double) _d; }
  610. inline ostream& _Cdecl ostream::operator<< (ostream& (*_f)(ostream&)) {
  611.                 return (*_f)(*this);
  612.                 }
  613. inline ostream& _Cdecl ostream::write(const unsigned char* _s, int _n) {
  614.                 return write((const signed char*)_s, _n);
  615.                 }
  616. inline ostream& _Cdecl ostream::put(char _c) {
  617.                 if( bp->sputc(_c) == EOF ) setstate(badbit);
  618.                 return *this;
  619.                 }
  620. #ifdef _BIG_INLINE_
  621. inline ostream& _Cdecl ostream::write(const signed char* _s, int _n) {
  622.                 if( ! fail() )
  623.                     if( bp->sputn((const char*)_s, _n) != _n )
  624.                         setstate(badbit);
  625.                 return *this;
  626.                 }
  627. #endif
  628.  
  629.  
  630. class iostream : public istream, public ostream {
  631. public:
  632.         _Cdecl iostream(streambuf*);
  633. virtual    _Cdecl ~iostream();
  634.  
  635. protected:
  636.         _Cdecl iostream();
  637. };
  638.  
  639.  
  640. class istream_withassign : public istream {
  641. public:
  642.         // does no initialization
  643.         _Cdecl istream_withassign();
  644.  
  645. virtual    _Cdecl ~istream_withassign();
  646.  
  647.     // gets buffer from istream and does entire initialization
  648.     istream_withassign& _Cdecl operator= (istream&);
  649.  
  650.     // associates streambuf with stream and does entire initialization
  651.     istream_withassign& _Cdecl operator= (streambuf*);
  652. };
  653.  
  654.  
  655. class ostream_withassign : public ostream {
  656. public:
  657.         // does no initialization
  658.         _Cdecl ostream_withassign();
  659.  
  660. virtual    _Cdecl ~ostream_withassign();
  661.  
  662.     // gets buffer from istream and does entire initialization
  663.     ostream_withassign& _Cdecl operator= (ostream&);
  664.  
  665.     // associates streambuf with stream and does entire initialization
  666.     ostream_withassign& _Cdecl operator= (streambuf*);
  667. };
  668.  
  669.  
  670. class iostream_withassign : public iostream {
  671. public:
  672.         // does no initialization
  673.         _Cdecl iostream_withassign();
  674.  
  675. virtual    _Cdecl ~iostream_withassign();
  676.  
  677.     // gets buffer from stream and does entire initialization
  678.     iostream_withassign& _Cdecl operator= (ios&);
  679.  
  680.     // associates streambuf with stream and does entire initialization
  681.     iostream_withassign& _Cdecl operator= (streambuf*);
  682. };
  683.  
  684.  
  685. /*
  686.  * The predefined streams
  687.  */
  688. extern istream_withassign _Cdecl cin;
  689. extern ostream_withassign _Cdecl cout;
  690. extern ostream_withassign _Cdecl cerr;
  691. extern ostream_withassign _Cdecl clog;
  692.  
  693. /*
  694.  * Manipulators
  695.  */
  696. ostream& _Cdecl endl(ostream&);    // insert newline and flush
  697. ostream& _Cdecl ends(ostream&);    // insert null to terminate string
  698. ostream& _Cdecl flush(ostream&);// flush the ostream
  699. ios&     _Cdecl dec(ios&);        // set conversion base to decimal
  700. ios&     _Cdecl hex(ios&);        // set conversion base to hexidecimal
  701. ios&     _Cdecl oct(ios&);        // set conversion base to octal
  702. istream& _Cdecl ws(istream&);    // extract whitespace characters
  703.  
  704. #endif
  705.