home *** CD-ROM | disk | FTP | other *** search
/ Tricks of the Windows Gam…ming Gurus (2nd Edition) / Disc2.iso / vc98 / crt / src / istream1.cpp < prev    next >
C/C++ Source or Header  |  1998-06-17  |  2KB  |  91 lines

  1. /***
  2. * istream1.cpp - non-core definitions for istream & istream_withassign classes
  3. *
  4. *       Copyright (c) 1991-1997, Microsoft Corporation.  All rights reserved.
  5. *
  6. *Purpose:
  7. *       Definitions of non-core member functions for istream and
  8. *       istream_withassign classes.
  9. *       [AT&T C++]
  10. *
  11. *******************************************************************************/
  12.  
  13. #include <cruntime.h>
  14. #include <internal.h>
  15. #include <stdlib.h>
  16. #include <iostream.h>
  17. #pragma hdrstop
  18.  
  19. istream& istream::operator>>(streambuf* _sbuf)
  20. {
  21.     int c;
  22.     if (ipfx(0))
  23.         {
  24.         while ((c=bp->sbumpc())!=EOF)
  25.             {
  26.             if (_sbuf->sputc(c)==EOF)
  27.                 {
  28.                 state |= ios::failbit;
  29.                 }
  30.             }
  31.         isfx();
  32.         }
  33. return *this;
  34. }
  35.  
  36.  
  37. // unformatted input functions
  38.  
  39. istream& istream::get( streambuf& sbuf, char delim)
  40. {
  41.     int c;
  42.     if (ipfx(1))        // resets x_gcount
  43.         {
  44.         while ((c  = bp->sgetc())!=delim)
  45.             {
  46.             if (c==EOF)  // stop if EOF encountered
  47.                 {
  48.                 state |= ios::eofbit;
  49.                 break;
  50.                 }
  51.             bp->stossc();       // advance get pointer
  52.             x_gcount++;         // and increment count
  53.  
  54.             if (sbuf.sputc(c)==EOF)
  55.                 state |= ios::failbit;
  56.             }
  57.         isfx();
  58.         }
  59.     return *this;
  60. }
  61.  
  62. istream& istream::seekg(streampos _strmp)
  63. {
  64.     lockbuf();
  65.     if (bp->seekpos(_strmp, ios::in)==EOF)
  66.         {
  67.         clear(state | failbit);
  68.         }
  69.     unlockbuf();
  70.     return(*this);
  71. }
  72.  
  73. istream& istream::seekg(streamoff _strmf, seek_dir _sd)
  74. {
  75.     lockbuf();
  76.     if (bp->seekoff(_strmf, _sd, ios::in)==EOF)
  77.         clear(state | failbit);
  78.     unlockbuf();
  79.     return(*this);
  80. }
  81.  
  82. streampos istream::tellg()
  83. {
  84.     streampos retval;
  85.     lockbuf();
  86.     if ((retval=bp->seekoff(streamoff(0), ios::cur, ios::in))==EOF)
  87.         clear(state | failbit);
  88.     unlockbuf();
  89.     return(retval);
  90. }
  91.