|
|
#include <iostream.h> class streambuf ; class ios ; class istream : virtual public ios ; class ostream : virtual public ios ; class iostream : public istream, public ostream ; class istream_withassign : public istream ; class ostream_withassign : public ostream ; class iostream_withassign : public iostream ;class Iostream_init ;
extern istream_withassign cin ; extern ostream_withassign cout ; extern ostream_withassign cerr ; extern ostream_withassign clog ;
#include <fstream.h> class filebuf : public streambuf ; class fstream : public iostream ; class ifstream : public istream ; class ofstream : public ostream ;
#include <strstream.h> class strstreambuf : public streambuf ; class istrstream : public istream ; class ostrstream : public ostream ;
#include <stdiostream.h> class stdiobuf : public streambuf ; class stdiostream : public ios ;
In the iostream man pages,
character
refers to a value that can be held in
either a char or unsigned char.
When functions that return an int
are said to return a character, they return a positive value.
Usually such functions can also return EOF (-1) as an error
indication.
The piece of memory that can hold a character is referred to as a
byte.
Thus, either a
char* or an unsigned char*
can point to an array of bytes.
The iostream package consists of several core classes, which provide the basic functionality for I/O conversion and buffering, and several specialized classes derived from the core classes. Both groups of classes are listed below.
streambufstreambuf
is described in
sbuf.pub(C++)
and the protected interface (for derived classes)
is described in
sbuf.prot(C++).
iosistreamstreambufs.
See
istream(C++).
ostreamstreambufs.
See
ostream(C++).
iostreamistream and ostream.
It is intended for situations in which bidirectional operations
(inserting into and extracting from a single sequence of characters)
are desired.
See
ios(C++).
istream_withassignostream_withassigniostream_withassigncin, cout, cerr,
and clog, are objects of these classes.
See
istream(C++),
ostream(C++),
and
ios(C++).
Iostream_initIostream_init constructor initializes the predefined streams
(listed below).
Because an object of this class is declared in the iostream.h header file,
the constructor is called once each time the header is included
(although the real initialization is only done once),
and therefore the predefined streams will be initialized before they
are used.
In some cases, global constructors may need to call the Iostream_init
constructor explicitly to ensure the standard streams are initialized
before they are used.
cincoutcerrostream::osfx() in
ostream(C++)
and ios::unitbuf
in
ios(C++).)
clogcerr its output is buffered.
cin, cerr, and clog are tied to cout so
that any use of these will cause cout to be flushed.
In addition to the core classes enumerated above, the iostream package contains additional classes derived from them and declared in other headers. Programmers may use these, or may choose to define their own classes derived from the core iostream classes.
streambuf
define the details of how
characters are produced or consumed.
Derivation of a class from streambuf (the protected
interface) is discussed in
sbuf.prot(C++).
The available buffer classes are:
filebufstdiobufFILE
structs.
It is intended for use when mixing C and C++ code.
New code should prefer to use
filebufs.
See
stdiobuf(C++).
strstreambufistream, ostream, and
iostream specialize the core classes for use
with particular kinds of streambufs.
These classes are:
ifstreamofstreamfstreamfilebuf
to do the I/O.
Common operations (such as opening and closing) can be done directly on
streams
without explicit mention of
filebufs.
See
fstream(C++).
istrstreamostrstreamstrstreambuf.
See
strstream(C++).
stdiostreamiostream for stdio FILEs.
See stdiostream.h.
streambuf
class of the old stream package that should have been private were public.
Most normal usage will compile properly, but any code that depends
on details, including classes that were derived from streambufs,
will have to be rewritten.
Performance of programs that copy from cin to cout
may sometimes be improved by breaking the tie between cin and
cout and doing explicit flushes of cout.
The header file stream.h exists for compatibility with
the earlier stream package.
It includes iostream.h, stdio.h, and some other headers, and
it declares some obsolete functions, enumerations, and variables.
Some members of streambuf and ios (not discussed in these manual
pages) are present only for backward compatibility with the stream package.