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

  1. /***
  2. * ostrulng.cpp - definitions for ostream class operator<<(unsigned long) funct
  3. *
  4. *       Copyright (c) 1991-1997, Microsoft Corporation.  All rights reserved.
  5. *
  6. *Purpose:
  7. *       Contains the member function definition for ostream
  8. *       operator<<(unsigned long).
  9. *
  10. *******************************************************************************/
  11.  
  12. #include <cruntime.h>
  13. #include <internal.h>
  14. #include <stdio.h>
  15. #include <iostream.h>
  16. #pragma hdrstop
  17.  
  18. ostream& ostream::operator<<(unsigned long n)
  19. {
  20. _WINSTATIC char obuffer[12];
  21. _WINSTATIC char fmt[4] = "%lu";
  22. _WINSTATIC char leader[4] = "\0\0";
  23.     if (opfx()) {
  24.         if (n)
  25.             {
  26.             if (x_flags & (hex|oct))
  27.                 {
  28.                 if (x_flags & hex)
  29.                     {
  30.                     if (x_flags & uppercase)
  31.                         fmt[2] = 'X';
  32.                     else
  33.                         fmt[2] = 'x';
  34.                     leader[1] = fmt[2];   // 0x or 0X  (or \0X)
  35.                     }
  36.                 else
  37.                     fmt[2] = 'o';
  38.                 if (x_flags & showbase)
  39.                     leader[0] = '0';
  40.                 }
  41.             else if (x_flags & showpos)
  42.                 {
  43.                 leader[0] = '+';
  44.                 }
  45.             }
  46.         sprintf(obuffer,fmt,n);
  47.         writepad(leader,obuffer);
  48.         osfx();
  49.     }
  50.     return *this;
  51.  
  52. }
  53.