home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 7 / 07.iso / c / c082_122 / 9.ddi / IOSTRSR1.ZIP / OSTPTR.CPP < prev    next >
Encoding:
C/C++ Source or Header  |  1992-06-10  |  1.7 KB  |  61 lines

  1. /*[]------------------------------------------------------------[]*/
  2. /*|                                                              |*/
  3. /*|     ostptr.cpp                                               |*/
  4. /*|                                                              |*/
  5. /*|     Class ostream                                            |*/
  6. /*|          ostream& ostream::operator<< (void* p)              |*/
  7. /*|                                                              |*/
  8. /*[]------------------------------------------------------------[]*/
  9.  
  10. /*
  11.  *      C/C++ Run Time Library - Version 5.0
  12.  *
  13.  *      Copyright (c) 1990, 1992 by Borland International
  14.  *      All Rights Reserved.
  15.  *
  16.  */
  17.  
  18. #include <ioconfig.h>
  19. #include <iostream.h>
  20.  
  21. // insert character representation of the value of the pointer
  22. ostream _FAR & ostream::operator<< (void* p)
  23. {
  24.     long f = flags();
  25.     setf((ios::hex | ios::showbase | ios::internal),
  26.          (ios::basefield | ios::showbase | ios::adjustfield));
  27.     fill('0');
  28.  
  29. #ifndef SHOW_COLON
  30.     /* Output without a separator */
  31. #if defined(__COMPACT__) || defined(__LARGE__) || defined(__HUGE__)
  32.     width(10);
  33.     *this << (unsigned long) p;
  34. #else
  35.     width(6);
  36.     *this << (unsigned) p;
  37. #endif
  38.  
  39. #else
  40.     /* Output with ':' separator */
  41.     width(6);
  42. #if defined(__LARGE__) || defined(__HUGE__) || defined(__COMPACT__)
  43.     *this << (unsigned)((unsigned long)p >> 16);
  44.     *this << ':';
  45. #ifndef SHOWBASE_ON_OFFSET
  46.     /* Don't show 0x on offset */
  47.     unsetf(ios::showbase);
  48.     width(4);
  49. #else
  50.     width(6);
  51. #endif  /* SHOWBASE_ON_OFFSET */
  52. #endif
  53.     *this << (unsigned)p;
  54. #endif  /* SHOW_COLON */
  55.  
  56.     flags(f);
  57.     return *this;
  58. }
  59.  
  60.  
  61.