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

  1. /***
  2. * istrlong.cpp - definitions for istream class operator>>(long) member function
  3. *
  4. *       Copyright (c) 1991-1997, Microsoft Corporation. All rights reserved.
  5. *
  6. *Purpose:
  7. *       Definitions of operator>>(long) member function(s) for istream class.
  8. *       [AT&T C++]
  9. *
  10. *******************************************************************************/
  11.  
  12. #include <cruntime.h>
  13. #include <internal.h>
  14. #include <stdlib.h>
  15. #include <limits.h>
  16. #include <errno.h>
  17. #include <iostream.h>
  18. #pragma hdrstop
  19.  
  20. /***
  21. *istream& istream::operator>>(long& n) - extract long
  22. *
  23. *Purpose:
  24. *       Extract long value from stream
  25. *
  26. *Entry:
  27. *       n = value to update
  28. *
  29. *Exit:
  30. *       n updated, or ios::failbit & n=LONG_MAX/LONG_MIN on overflow/underflow
  31. *
  32. *Exceptions:
  33. *       Stream error on entry or value out of range
  34. *
  35. *******************************************************************************/
  36. istream& istream::operator>>(long& n)
  37. {
  38. _WINSTATIC char ibuffer[MAXLONGSIZ];
  39.     char ** endptr = (char**)NULL;
  40.     if (ipfx(0)) {
  41.         n = strtol(ibuffer, endptr, getint(ibuffer));
  42.         if (errno==ERANGE)
  43.             {
  44.             state |= ios::failbit;
  45.             }
  46.  
  47.         isfx();
  48.     }
  49. return *this;
  50. }
  51.