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

  1. /***
  2. * istruint.cpp - definitions for istream class operaotor>>(unsigned int) funct
  3. *
  4. *       Copyright (c) 1991-1997, Microsoft Corporation.  All rights reserved.
  5. *
  6. *Purpose:
  7. *       Definitions of operator>>(unsigned int) member function 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 int& n) - extract unsigned int
  23. *
  24. *Purpose:
  25. *       Extract unsigned int value from stream
  26. *       Valid range is INT_MIN to UINT_MAX.
  27. *
  28. *Entry:
  29. *       n = value to update
  30. *
  31. *Exit:
  32. *       n updated, or ios::failbit and n=UINT_MAX if error
  33. *
  34. *Exceptions:
  35. *       Stream error on entry or value out of range
  36. *
  37. *******************************************************************************/
  38. istream& istream::operator>>(unsigned int& n)
  39. {
  40. _WINSTATIC char ibuffer[MAXLONGSIZ];
  41.     unsigned long value;
  42.     char ** endptr = (char**)NULL;
  43.     if (ipfx(0)) {
  44.         value = strtoul(ibuffer, endptr, getint(ibuffer));
  45.  
  46.         if (((value>UINT_MAX) && (value<=(ULONG_MAX-(unsigned long)(-INT_MIN))))
  47.                 || ((value==ULONG_MAX) && (errno==ERANGE)))
  48.             {
  49.             n = UINT_MAX;
  50.             state |= ios::failbit;
  51.             }
  52.         else
  53.             n = (unsigned int) value;
  54.  
  55.         isfx();
  56.         }
  57. return *this;
  58. }
  59.