home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 7 / 07.iso / c / c065 / 2.ddi / CLIB2.ZIP / MANIP.CPP < prev    next >
Encoding:
C/C++ Source or Header  |  1990-06-07  |  2.1 KB  |  94 lines

  1. /*-----------------------------------------------------------------------*
  2.  * filename - manip.cpp
  3.  * Predefined manipulators
  4.  *-----------------------------------------------------------------------*/
  5.  
  6. /*[]------------------------------------------------------------[]*/
  7. /*|                                                              |*/
  8. /*|     Turbo C++ Run Time Library - Version 1.0                 |*/
  9. /*|                                                              |*/
  10. /*|                                                              |*/
  11. /*|     Copyright (c) 1990 by Borland International              |*/
  12. /*|     All Rights Reserved.                                     |*/
  13. /*|                                                              |*/
  14. /*[]------------------------------------------------------------[]*/
  15.  
  16. #include <iostream.h>
  17. #include <iomanip.h>
  18.  
  19.  
  20. // set the conversion base to 0, 8, 10, or 16
  21. static ios& sbase(ios& i, int b)
  22. {
  23.     long l = 0;
  24.     if( b == 16 ) l = ios::hex;
  25.     else if (b == 10) l = ios::dec;
  26.     else if( b == 8 ) l = ios::oct;
  27.     i.setf(l, ios::basefield);
  28.     return i;
  29. }
  30. smanip_int setbase(int b)
  31. {
  32.     return smanip_int(sbase, b);
  33. }
  34.  
  35.  
  36. // clear the flags bitvector according to the bits set in b
  37. static ios& rsios(ios& i, long b)
  38. {
  39.     i.unsetf(b);
  40.     return i;
  41. }
  42. smanip_long resetiosflags(long b)
  43. {
  44.     return smanip_long(rsios, b);
  45. }
  46.  
  47.  
  48. // set the flags bitvector according to the bits set in b
  49. static ios& sios(ios& i, long b)
  50. {
  51.     i.setf(b);
  52.     return i;
  53. }
  54. smanip_long setiosflags(long b)
  55. {
  56.     return smanip_long(sios, b);
  57. }
  58.  
  59.  
  60. // set fill character for padding a field
  61. static ios& sfill(ios& i, int f)
  62. {
  63.     i.fill(f);
  64.     return i;
  65. }
  66. smanip_int setfill(int f)
  67. {
  68.     return smanip_int(sfill, f);
  69. }
  70.  
  71.  
  72. // set the floating-point precision to n digits
  73. static ios& sprec(ios& i, int n)
  74. {
  75.     i.precision(n);
  76.     return i;
  77. }
  78. smanip_int setprecision(int n)
  79. {
  80.     return smanip_int(sprec, n);
  81. }
  82.  
  83.  
  84. // set the field width to n
  85. static ios& swidth(ios& i, int n)
  86. {
  87.     i.width(n);
  88.     return i;
  89. }
  90. smanip_int setw(int n)
  91. {
  92.     return smanip_int(swidth, n);
  93. }
  94.