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

  1. /*[]------------------------------------------------------------[]*/
  2. /*|                                                              |*/
  3. /*|     filename - istgline.cpp                                  |*/
  4. /*|                                                              |*/
  5. /*|     Class istream                                            |*/
  6. /*|          istream& istream::getline( signed char*, int, char )|*/
  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 characters into an array, reading and discarding delimiter d
  22.  
  23. istream _FAR & istream::getline(signed char* p, int len, char d)
  24. {
  25.     if( ipfx1() )
  26.         {
  27.         signed char* op = p;
  28.         int c = 0;
  29.         while( --len > 0  &&  (c = bp->sgetc()) != EOF )
  30.             {
  31.             ++gcount_;
  32.             bp->stossc();
  33.             if( c == d )
  34.                 break;
  35.             *p++ = c;
  36.             }
  37.         if( c == EOF )
  38.             setstate((p == op) ? (ios::eofbit | ios::failbit) : ios::eofbit);
  39.         }
  40.     else
  41.         setstate(ios::failbit);
  42.  
  43.     *p = 0; // always terminate with a null
  44.     return *this;
  45. }
  46.  
  47.  
  48.