|
|
#include <iostream.h> #include <iomanip.h>IOMANIPdeclare(T) ;
class SMANIP(T) { SMANIP(T)( ios& (*)(ios&,T), T); friend istream& operator>>(istream&, SMANIP(T)&); friend ostream& operator<<(ostream&, SMANIP(T)&); }; class SAPP(T) { SAPP(T)( ios& (*)(ios&,T)); SMANIP(T) operator()(T); }; class IMANIP(T) { IMANIP(T)( istream& (*)(istream&,T), T); friend istream& operator>>(istream&, IMANIP(T)&); }; class IAPP(T) { IAPP(T)( istream& (*)(istream&,T)); IMANIP(T) operator()(T); }; class OMANIP(T) { OMANIP(T)( ostream& (*)(ostream&,T), T); friend ostream& operator<<(ostream&, OMANIP(T)&); }; class OAPP(T) { OAPP(T)( ostream& (*)(ostream&,T)); OMANIP(T) operator()(T); }; class IOMANIP(T) { IOMANIP(T)( iostream& (*)(iostream&,T), T); friend istream& operator>>(iostream&, IOMANIP(T)&); friend ostream& operator<<(iostream&, IOMANIP(T)&); }; class IOAPP(T) { IOAPP(T)( iostream& (*)(iostream&,T)); IOMANIP(T) operator()(T); };
IOMANIPdeclare(int); IOMANIPdeclare(long);
SMANIP(long) resetiosflags(long); SMANIP(int) setfill(int); SMANIP(long) setiosflags(long); SMANIP(int) setprecision(int); SMANIP(int) setw(int w);
Ideally, the types relating to manipulators would be parameterized as "templates." The macros defined in iomanip.h are used to simulate templates. IOMANIPdeclare(T) declares the various classes and operators. (All code is declared inline so that no separate definitions are required.) Each of the other Ts is used to construct the real names and therefore must be a single identifier. Each of the other macros also requires an identifier and expands to a name.
In the following descriptions, assume:
-- t is a T, or type name.
-- s is an ios.
-- i is an istream.
-- o is an ostream.
-- io is an iostream.
-- f is an ios& (*)(ios&).
-- if is an istream& (*)(istream&).
-- of is an ostream& (*)(ostream&).
-- iof is an iostream& (*)(iostream&).
-- n is an int.
-- l is a long.
iomanip.h contains two declarations, IOMANIPdeclare(int) and IOMANIPdeclare(long) and some manipulators that take an int or a long argument. These manipulators all have to do with changing the format state of a stream; see ios(3C++) for further details.