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

  1. /***
  2. * ostrint.cpp - definitions for ostream class operator<<(int) member functions
  3. *
  4. *       Copyright (c) 1991-1997, Microsoft Corporation.  All rights reserved.
  5. *
  6. *Purpose:
  7. *       Contains the member function definitions for ostream operator<<(int).
  8. *
  9. *******************************************************************************/
  10.  
  11. #include <cruntime.h>
  12. #include <internal.h>
  13. #include <stdio.h>
  14. #include <iostream.h>
  15. #pragma hdrstop
  16.  
  17. ostream& ostream::operator<<(int n)
  18. {
  19. _WINSTATIC char obuffer[12];
  20. _WINSTATIC char fmt[4] = "%d";
  21. _WINSTATIC char leader[4] = "\0\0";
  22.     if (opfx()) {
  23.  
  24.         if (n)
  25.             {
  26.             if (x_flags & (hex|oct))
  27.                 {
  28.                 if (x_flags & hex)
  29.                     {
  30.                     if (x_flags & uppercase)
  31.                         fmt[1] = 'X';
  32.                     else
  33.                         fmt[1] = 'x';
  34.                     leader[1] = fmt[1];   // 0x or 0X  (or \0X)
  35.                     }
  36.                 else
  37.                     fmt[1] = 'o';
  38.                 if (x_flags & showbase)
  39.                     leader[0] = '0';
  40.                 }
  41.             else if ((n>0) && (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.