manip(3C++)


manip -- iostream out of band manipulations

Synopsis

   #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);

Description

Manipulators are values that may be ``inserted into'' or ``extracted from'' streams to achieve some effect (other than to insert or extract a value representation), with a convenient syntax. They enable one to embed a function call in an expression containing a series of insertions or extractions. For example, the predefined manipulator for ostreams, flush, can be used as follows:
cout << flush
to flush cout. Several iostream classes supply manipulators: see ios(3C++), istream(3C++), and ostream(3C++). flush is a simple manipulator; some manipulators take arguments, such as the predefined ios manipulators, setfill and setw (see below). The header file iomanip.h supplies macro definitions which programmers can use to define new parameterized manipulators.

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.


s<<SMANIP(T)(f,t)

s>>SMANIP(T)(f,t)

s<<SAPP(T)(f)(t)

s>>SAPP(T)(f)(t)
Returns f(s,t), where s is the left operand of the insertion or extractor operator (i.e., s, i, o, or io).

i>>IMANIP(T)(if,t)

i>>IAPP(T)(if)(t)
Returns if(i,t).

o<<OMANIP(T)(of,t)

o<<OAPP(T)(of)(t)
Returns of(o,t).

io<<IOMANIP(T)(iof,t)

io>>IOMANIP(T)(iof,t)

io<<IOAPP(T)(iof)(t)

io>>IOAPP(T)(iof)(t)
Returns iof(io,t).

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.


o<<setw(n)

i>>setw(n)
Sets the field width of the stream (left-hand operand: o or i) to n.

o<<setfill(n)

i>>setfill(n)
Sets the fill character of the stream (o or i) to be n.

o<<setprecision(n)

i>>setprecision(n)
Sets the precision of the stream (o or i) to be n.

o<<setiosflags(l)

i>>setiosflags(l)
Turns on in the stream (o or i) the format flags marked in l. (Calls o.setf(l) or i.setf(l)).

o<<resetiosflags(l)

i>>resetiosflags(l)
Clears in the stream (o or i) the format bits specified by l. (Calls o.setf(0,l) or i.setf(0,l)).

Diagnostics

Syntax errors will be reported if IOMANIPdeclare(T) occurs more than once in a file with the same T.

References

ios(3C++), istream(3C++), ostream(3C++)


© 2004 The SCO Group, Inc. All rights reserved.
UnixWare 7 Release 7.1.4 - 25 April 2004