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

  1. /***
  2. * istrgetl.cpp - definitions for istream class get() member function
  3. *
  4. *       Copyright (c) 1991-1997, Microsoft Corporation.  All rights reserved.
  5. *
  6. *Purpose:
  7. *       Definitions of get and getline member functions 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. // signed and unsigned char make inline calls to this:
  20. // all versions of getline also share this code:
  21.  
  22. istream& istream::get( char *b, int lim, int delim)
  23. {
  24.         int c;
  25.         unsigned int i = 0;
  26.         if (ipfx(1))    // resets x_gcount
  27.         {
  28.             if (lim--)
  29.             {
  30.                 while (i < (unsigned)lim)
  31.                 {
  32.                     c = bp->sgetc();
  33.                     if (c == EOF)
  34.                     {
  35.                         state |= ios::eofbit;
  36.                         if (!i)
  37.                             state |= ios::failbit;
  38.                         break;
  39.                     }
  40.                     else if (c == delim)
  41.                     {
  42.                         if (_fGline)
  43.                         {
  44.                             x_gcount++;
  45.                             bp->stossc(); // extract delim if called from getline
  46.                         }
  47.                         break;
  48.                     }
  49.                     else
  50.                     {
  51.                         if (b)
  52.                             b[i] = (char)c;
  53.                         bp->stossc(); // advance pointer
  54.                     }
  55.                     i++;
  56.                 }
  57.                 x_gcount += i;      // set gcount()
  58.             }
  59.             isfx();
  60.             lim++;      // restore lim for test below
  61.         }
  62.         if ((b) && (lim))   // always null-terminate, if possible
  63.             b[i] = '\0';
  64.         _fGline = 0;
  65.  
  66.         return *this;
  67. }
  68.