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

  1. /***
  2. * ostrusht.cpp - definition for ostream class operator<<(unsigned short) 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 short).
  9. *
  10. *******************************************************************************/
  11.  
  12. #include <cruntime.h>
  13. #include <internal.h>
  14. #include <stdlib.h>
  15. #include <stdio.h>
  16. #include <iostream.h>
  17. #pragma hdrstop
  18.  
  19. ostream& ostream::operator<<(unsigned short n)
  20. {
  21. _WINSTATIC char obuffer[8];
  22. _WINSTATIC char fmt[4] = "%hu";
  23. _WINSTATIC char leader[4] = "\0\0";
  24.     if (opfx()) {
  25.         if (n)
  26.             {
  27.             if (x_flags & (hex|oct))
  28.                 {
  29.                 if (x_flags & hex)
  30.                     {
  31.                     if (x_flags & uppercase)
  32.                         fmt[2] = 'X';
  33.                     else
  34.                         fmt[2] = 'x';
  35.                     leader[1] = fmt[2];   // 0x or 0X  (or \0X)
  36.                     }
  37.                 else
  38.                     fmt[2] = 'o';
  39.                 if (x_flags & showbase)
  40.                     leader[0] = '0';
  41.                 }
  42.             else if (x_flags & showpos)
  43.                 {
  44.                 leader[0] = '+';
  45.                 }
  46.             }
  47.         sprintf(obuffer,fmt,n);
  48.         writepad(leader,obuffer);
  49.         osfx();
  50.     }
  51.     return *this;
  52.  
  53. }
  54.