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

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