Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

57 lines
1.2 KiB

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