Leaked source code of windows server 2003
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.

56 lines
1.2 KiB

  1. /***
  2. * ostrlong.cpp - definitions for ostream class operator<<(long) member functions
  3. *
  4. * Copyright (c) 1991-2001, Microsoft Corporation. All rights reserved.
  5. *
  6. *Purpose:
  7. * Contains the member function definitions for ostream operator<<(long).
  8. *
  9. *Revision History:
  10. * 09-23-91 KRS Created. Split out from ostream.cxx for granularity.
  11. * 06-14-95 CFW Comment cleanup.
  12. *
  13. *******************************************************************************/
  14. #include <cruntime.h>
  15. #include <internal.h>
  16. #include <stdio.h>
  17. #include <iostream.h>
  18. #pragma hdrstop
  19. ostream& ostream::operator<<(long n)
  20. {
  21. _WINSTATIC char obuffer[12];
  22. _WINSTATIC char fmt[4] = "%ld";
  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 ((n>0) && (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. }