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

  1. /*[]------------------------------------------------------------[]*/
  2. /*|                                                              |*/
  3. /*|     istebuf.cpp                                              |*/
  4. /*|                                                              |*/
  5. /*|     Class istream                                            |*/
  6. /*|          istream& istream::operator>> ( streambuf * )        |*/
  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 <ioconfig.h>
  19. #include <iostream.h>
  20.  
  21. // extract from this istream, insert into streambuf
  22.  
  23. istream _FAR & istream::operator>> (streambuf* s)
  24. {
  25.     enum errkind { noerr, nodata, putfail } err;
  26.     if( ipfx0() )
  27.         {
  28.         err = nodata;
  29.         int c;
  30.         while( (c = bp->sgetc()) != EOF )
  31.             {
  32.             if( s->sputc(c) == EOF )
  33.                 {
  34.                 err = putfail;
  35.                 break;
  36.                 }
  37.             err = noerr;
  38.             bp->stossc();
  39.             }
  40.         int errstate = ( err == noerr ) ? 0 : ios::failbit;
  41.         if( c == EOF )
  42.             {
  43.             errstate |= ios::eofbit;
  44.             if( err == nodata )
  45.                 errstate |= ios::badbit;
  46.             }
  47.         if( errstate )
  48.             setstate(errstate);
  49.         }
  50.     return *this;
  51. }
  52.