#include <IoFormat.h>
These classes are based on Bjarne Stroustrup's The C++ Programming Language 3rd Ed. Special Edition, p.635, User-Defined Manipulators [2000].
Here is an example of its use.
Rulbus::IoFormat<double> sci;
Rulbus::IoFormat<double> alt;
sci.scientific().width(12).precision(3);
alt.showplus().width(12).right().fill('#');
double d = 1234.5678;
std::cout << d << " '" << sci(d) << "'" << " '" << alt(d) << "'" << std::endl;
This produces the following output.
1234.57 ' 1.235e+03' '+####1234.57'
Public Types | |
| typedef std::ios_base::fmtflags | fmtflags |
| shorthand type definition. | |
Public Member Functions | |
Construction | |
| IoFormat (int precision=6) | |
| (default) constructor. | |
Operators | |
| BoundIoFormat< T > | operator() (const T &d) const |
| bind a value to a format. | |
Accessors | |
| int | fill () const |
| the fill character. | |
| int | flags () const |
| the format flags. | |
| int | width () const |
| the minimum field width. | |
| int | precision () const |
| the precision. | |
Mutators | |
| IoFormat< T > & | left () |
| adjust left. | |
| IoFormat< T > & | right () |
| adjust right. | |
| IoFormat< T > & | internal () |
| adjust right, but sign is left. | |
| IoFormat< T > & | boolalpha (bool alpha=true) |
| show boolean as true, false. | |
| IoFormat< T > & | uppercase (bool upper=true) |
| use uppercase for X and E and for hexadecimal characters. | |
| IoFormat< T > & | general () |
| use default format. | |
| IoFormat< T > & | fixed () |
| use fixed format. | |
| IoFormat< T > & | scientific () |
| use scientific format. | |
| IoFormat< T > & | oct () |
| use octal representation. | |
| IoFormat< T > & | dec () |
| use decimal representation. | |
| IoFormat< T > & | hex () |
| use hexadecimal representation. | |
| IoFormat< T > & | showplus (bool show=true) |
| show plus sign. | |
| IoFormat< T > & | showbase (bool show=true) |
| show representation base (0, for octal, 0x for hexadecimal). | |
| IoFormat< T > & | showpoint (bool show=true) |
| always show point. | |
| IoFormat< T > & | fill (int c= ' ') |
| set fill character. | |
| IoFormat< T > & | width (int w) |
| set minimum field width. | |
| IoFormat< T > & | precision (int p) |
| set precision. | |
Protected Member Functions | |
| void | setf (fmtflags f) |
| set format flag. | |
| void | setf (fmtflags f, fmtflags msk) |
| set format flag(s) within field. | |
| void | unsetf (fmtflags msk=~0) |
| clear format flag(s). | |
Private Attributes | |
Data | |
| int | thePrecision |
| precision | |
| int | theWidth |
| width | |
| int | theFillChar |
| fill character | |
| fmtflags | theFlags |
| flags | |