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

  1. /***
  2. * istrget.cpp - definitions for istream class get() member functions
  3. *
  4. *       Copyright (c) 1991-1997, Microsoft Corporation.  All rights reserved.
  5. *
  6. *Purpose:
  7. *       Definitions of get() member functions for istream class.
  8. *       [AT&T C++]
  9. *
  10. *******************************************************************************/
  11.  
  12. #include <cruntime.h>
  13. #include <internal.h>
  14. #include <iostream.h>
  15. #pragma hdrstop
  16.  
  17. // unformatted input functions
  18.  
  19. int istream::get()
  20. {
  21.     int c;
  22.     if (ipfx(1))        // resets x_gcount
  23.         {
  24.         if ((c=bp->sbumpc())==EOF)
  25.             state |= ios::eofbit;
  26.         else
  27.             x_gcount++;
  28.         isfx();
  29.         return c;
  30.         }
  31.     return EOF;
  32. }
  33.  
  34. // signed and unsigned char make inline calls to this:
  35. istream& istream::get( char& c)
  36. {
  37.     int temp;
  38.     if (ipfx(1))        // resets x_gcount
  39.         {
  40.         if ((temp=bp->sbumpc())==EOF)
  41.             state |= (ios::failbit|ios::eofbit);
  42.         else
  43.             x_gcount++;
  44.         c = (char) temp;
  45.         isfx();
  46.         }
  47.     return *this;
  48. }
  49.  
  50.  
  51. // called by signed and unsigned char versions
  52. istream& istream::read(char * ptr, int n)
  53. {
  54.     if (ipfx(1))        // resets x_gcount
  55.         {
  56.         x_gcount = bp->sgetn(ptr, n);
  57.         if ((unsigned)x_gcount < (unsigned)n)
  58.             state |= (ios::failbit|ios::eofbit);
  59.         isfx();
  60.         }
  61.     return *this;
  62. }
  63.