📄 ostream_.gml
字号:
:CLFNM.ostream
:CMT.========================================================================
:LIBF fmt='hdr'.ostream
:HFILE.iostream.h
:DVFML.
:DVFM.ios
:eDVFML.
:DVBYL.
:DVBY.iostream
:DVBY.ofstream
:DVBY.ostrstream
:eDVBYL.
:CLSS.
The &cls. supports writing characters to a class derived from the
:MONO.streambuf
class, and provides formatted conversion of types (such as integers and
floating-point numbers) into characters. The class derived from the
:MONO.streambuf
class provides the methods for communicating with the external device
(screen, disk), while the &cls. provides the conversion of the types into
characters.
:P.
Generally, &obj.s won't be explicitly created by a program, since there
is no mechanism at this level to open a device. The only default
&obj.s in a program are &cout., &cerr., and &clog. which write to the
standard output and error devices (usually the screen).
:P.
The &cls. supports two basic concepts of output: formatted and unformatted.
The overloaded
:MONO.operator~b<<
member functions are called
:ITALICS.inserters
:I1.inserter
and they provide the support for formatted output. The rest of the member
functions deal with unformatted output, managing the state of the
:MONO.ios
object and providing a friendlier interface to the associated
:MONO.streambuf
object.
:HDG.Protected Member Functions
The following protected member functions are declared:
:MFNL.
:MFCD cd_idx='c'.ostream();
:eMFNL.
:HDG.Public Member Functions
The following public member functions are declared:
:MFNL.
:MFCD cd_idx='c'.ostream( ostream const & );
:MFCD cd_idx='c'.ostream( streambuf * );
:MFCD cd_idx='d' .virtual ~~ostream();
:MFN index='flush' .ostream &.flush();
:MFN index='opfx' .int opfx();
:MFN index='osfx' .void osfx();
:MFN index='put' .ostream &.put( char );
:MFN index='put' .ostream &.put( signed char );
:MFN index='put' .ostream &.put( unsigned char );
:MFN index='seekp' .ostream &.seekp( streampos );
:MFN index='seekp' .ostream &.seekp( streamoff, ios::seekdir );
:MFN index='tellp' .streampos tellp();
:MFN index='write' .ostream &.write( char const *, int );
:MFN index='write' .ostream &.write( signed char const *, int );
:MFN index='write' .ostream &.write( unsigned char const *, int );
:eMFNL.
:HDG.Public Member Operators
The following public member operators are declared:
:MFNL.
:MFN index='operator =' .ostream &.operator =( streambuf * );
:MFN index='operator =' .ostream &.operator =( ostream const & );
:MFN index='operator <<'.ostream &.operator <<( char );
:MFN index='operator <<'.ostream &.operator <<( signed char );
:MFN index='operator <<'.ostream &.operator <<( unsigned char );
:MFN index='operator <<'.ostream &.operator <<( signed short );
:MFN index='operator <<'.ostream &.operator <<( unsigned short );
:MFN index='operator <<'.ostream &.operator <<( signed int );
:MFN index='operator <<'.ostream &.operator <<( unsigned int );
:MFN index='operator <<'.ostream &.operator <<( signed long );
:MFN index='operator <<'.ostream &.operator <<( unsigned long );
:MFN index='operator <<'.ostream &.operator <<( float );
:MFN index='operator <<'.ostream &.operator <<( double );
:MFN index='operator <<'.ostream &.operator <<( long double );
:MFN index='operator <<'.ostream &.operator <<( void * );
:MFN index='operator <<'.ostream &.operator <<( streambuf & );
:MFN index='operator <<'.ostream &.operator <<( char const * );
:MFN index='operator <<'.ostream &.operator <<( signed char const * );
:MFN index='operator <<'.ostream &.operator <<( unsigned char const * );
:MFN index='operator <<'.ostream &.operator <<( ostream &(*)( ostream & ) );
:MFN index='operator <<'.ostream &.operator <<( ios &(*)( ios & ) );
:eMFNL.
:eCLSS.
:SALSO.
:SAL typ='cls'.ios
:SAL typ='cls'.iostream
:SAL typ='cls'.istream
:eSALSO.
:eLIBF.
:CMT.========================================================================
:LIBF fmt='mfun' prot='public'.flush
:SNPL.
:SNPFLF .#include <iostream.h>
:SNPFLF .public:
:SNPF index='flush'.ostream &.ostream::flush();
:eSNPL.
:SMTICS.
The &fn. causes the &obj.'s buffers to be flushed, forcing the contents to
be written to the actual device connected to the &obj.:PERIOD.
:RSLTS.
The &fn. returns a reference to the &obj.:PERIOD.
On failure, &failbit. is set in the &errstate.:PERIOD.
:SALSO.
:SAL typ='mfun'.osfx
:eSALSO.
:eLIBF.
:CMT.========================================================================
:LIBF fmt='mfun' prot='public'.operator <<
:SNPL.
:SNPFLF .#include <iostream.h>
:SNPFLF .public:
:SNPF index='operator <<'.ostream &.ostream::operator <<( char ch );
:SNPF index='operator <<'.ostream &.ostream::operator <<( signed char ch );
:SNPF index='operator <<'.ostream &.ostream::operator <<( unsigned char ch );
:eSNPL.
:SMTICS.
These forms of the &fn. write the
:ARG.ch
character into the &obj.:PERIOD.
:RSLTS.
These forms of the &fn. return a reference to the &obj. so that further
insertion operations may be specified in the same statement.
&failbit. is set in the &errstate. if an error occurs.
:SALSO.
:SAL typ='mfun'.put
:eSALSO.
:eLIBF.
:CMT.========================================================================
:LIBF fmt='mfun' prot='public'.operator <<
:SNPL.
:SNPFLF .#include <iostream.h>
:SNPFLF .public:
:SNPF index='operator <<'.ostream &.ostream::operator <<( char const *str );
:SNPF index='operator <<'.ostream &.ostream::operator <<( signed char const *str );
:SNPF index='operator <<'.ostream &.ostream::operator <<( unsigned char const *str );
:eSNPL.
:SMTICS.
These forms of the &fn. perform a formatted write of the contents of the C string specified by the
:ARG.str
parameter to the &obj.:PERIOD.
The characters from
:ARG.str
are transferred up to, but not including the terminating null character.
:RSLTS.
These forms of the &fn. return a reference to the &obj. so that further
insertion operations may be specified in the same statement.
&failbit. is set in the &errstate. if an error occurs.
:eLIBF.
:CMT.========================================================================
:LIBF fmt='mfun' prot='public'.operator <<
:SNPL.
:SNPFLF .#include <iostream.h>
:SNPFLF .public:
:SNPF index='operator <<'.ostream &.ostream::operator <<( signed int num );
:SNPF index='operator <<'.ostream &.ostream::operator <<( unsigned int num );
:SNPF index='operator <<'.ostream &.ostream::operator <<( signed long num );
:SNPF index='operator <<'.ostream &.ostream::operator <<( unsigned long num );
:SNPF index='operator <<'.ostream &.ostream::operator <<( signed short num );
:SNPF index='operator <<'.ostream &.ostream::operator <<( unsigned short num );
:eSNPL.
:SMTICS.
These forms of the &fn. perform a formatted write of the integral value specified by the
:ARG.num
parameter to the &obj.:PERIOD.
The integer value is converted to a string of characters which are
written to the &obj.:PERIOD.
:ARG.num
is converted to a base representation depending on the setting of the
:MONO.ios::basefield
bits in &fmtflags.:PERIOD.
If the
:MONO.ios::oct
bit is the only bit on, the conversion is to an octal (base 8)
representation. If the
:MONO.ios::hex
bit is the only bit on, the conversion is to a hexadecimal (base 16)
representation. Otherwise, the conversion is to a decimal (base 10)
representation.
:P.
For decimal conversions only, a sign may be written in front of the
number. If the number is negative, a
:MONO.-
minus sign is written. If the number is positive and the
:MONO.ios::showpos
bit is on in &fmtflags., a
:MONO.+
plus sign is written. No sign is written for a value of zero.
:P.
If the
:MONO.ios::showbase
bit is on in &fmtflags., and the conversion is to octal or hexadecimal,
the base indicator is written next. The base indicator for a conversion
to octal is a zero. The base indicator for a conversion to hexadecimal is
:MONO.0x
or
:MONO.0X
:CONT., depending on the setting of the
:MONO.ios::uppercase
bit in &fmtflags.:PERIOD.
:P.
If the value being written is zero, the conversion is to octal, and the
:MONO.ios::showbase
bit is on, nothing further is written since a single zero is
sufficient.
:P.
The value of
:ARG.num
is then converted to characters. For conversions to decimal, the magnitude of
the number is converted to a string of decimal digits
:MONO.0123456789
:PERIOD.
For conversions to octal, the number is treated as an unsigned quantity
and converted to a string of octal digits
:MONO.01234567
:PERIOD.
For conversions to hexadecimal, the number is treated as an unsigned
quantity and converted to a string of hexadecimal digits
:MONO.0123456789
and the letters
:MONO.abcdef
or
:MONO.ABCDEF
:CONT., depending on the setting of the
:MONO.ios::uppercase
in &fmtflags.:PERIOD.
The string resulting from the conversion is then written to the &obj.:PERIOD.
:P.
If the
:MONO.ios::internal
bit is set in &fmtflags. and padding is required, the padding characters
are written after the sign and/or base indicator (if present)
and before the digits.
:RSLTS.
These forms of the &fn. return a reference to the &obj. so that further
insertion operations may be specified in the same statement.
&failbit. is set in the &errstate. if an error occurs.
:eLIBF.
:CMT.========================================================================
:LIBF fmt='mfun' prot='public'.operator <<
:SNPL.
:SNPFLF .#include <iostream.h>
:SNPFLF .public:
:SNPF index='operator <<'.ostream &.ostream::operator <<( float num );
:SNPF index='operator <<'.ostream &.ostream::operator <<( double num );
:SNPF index='operator <<'.ostream &.ostream::operator <<( long double num );
:eSNPL.
:SMTICS.
These forms of the &fn. perform a formatted write of the floating-point value specified by the
:ARG.num
parameter to the &obj.:PERIOD.
The number is converted to either scientific (exponential) form or
fixed-point form, depending on the setting of the
:MONO.ios::floatfield
bits in &fmtflags.:PERIOD.
If
:MONO.ios::scientific
is the only bit set, the conversion is to scientific form. If
:MONO.ios::fixed
is the only bit set, the conversion is to fixed-point form.
Otherwise (neither or both bits set), the value of the number determines
the conversion used. If the exponent is less than -4 or is greater than or
equal to the &fmtprec., the scientific form is used.
Otherwise, the fixed-point form is used.
:P.
Scientific form consists of a minus sign (for negative numbers), one
digit, a decimal point, &fmtprec.-1 digits, an
:MONO.e
or
:MONO.E
(depending on the setting of the
:MONO.ios::uppercase
bit), a minus sign (for negative exponents) or a plus sign (for zero or
positive exponents), and two or three digits for the exponent.
The digit before the decimal is not zero, unless the number is zero.
If the &fmtprec. is zero (or one), no digits are written following
the decimal point.
:P.
Fixed-point form consists of a minus sign (for negative numbers),
one or more digits, a decimal point, and &fmtprec. digits.
:P.
If the
:MONO.ios::showpoint
bit is not set in &fmtflags., trailing zeroes are trimmed after the
decimal point (and before the exponent for scientific form), and if no digits
remain after the decimal point, the decimal point is discarded as well.
:P.
If the
:MONO.ios::internal
bit is set in &fmtflags. and padding is required, the padding
characters are written after the sign (if present) and before the digits.
:RSLTS.
These forms of the &fn. return a reference to the &obj. so that further
insertion operations may be specified in the same statement.
&failbit. is set in the &errstate. if an error occurs.
:eLIBF.
:CMT.========================================================================
:LIBF fmt='mfun' prot='public'.operator <<
:SNPL.
:SNPFLF .#include <iostream.h>
:SNPFLF .public:
:SNPF index='operator <<'.ostream &.ostream::operator <<( void *ptr );
:eSNPL.
:SMTICS.
This form of the &fn. performs a formatted write of the pointer value specified by the
:ARG.ptr
parameter to the &obj.:PERIOD.
The
:ARG.ptr
parameter is converted to an implementation-defined string of characters and
written to the &obj.:PERIOD.
With the &cmppname implementation, the string starts with
:MONO.0x
or
:MONO.0X
(depending on the setting of the
:MONO.ios::uppercase
bit),
followed by
4 hexadecimal digits for 16-bit pointers and 8 hexadecimal
digits for 32-bit pointers. Leading zeroes are added to ensure the correct
number of digits are written.
For far pointers, 4 additional hexadecimal digits and a colon are inserted
immediately after the
:MONO.0x
prefix.
:RSLTS.
This form of the &fn. returns a reference to the &obj. so that further
insertion operations may be specified in the same statement.
&failbit. is set in the &errstate. if an error occurs during the write.
:eLIBF.
:CMT.========================================================================
:LIBF fmt='mfun' prot='public'.operator <<
:SNPL.
:SNPFLF .#include <iostream.h>
:SNPFLF .public:
:SNPF index='operator <<'.ostream &.ostream::operator <<( streambuf &.sb );
:eSNPL.
:SMTICS.
This form of the &fn. transfers the contents of the
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -