The Iostream Library Is An Object
The Iostream Library Is An Object
The Iostream Library Is An Object
using streams.
Definition:
A stream is an abstraction that represents a device on which input and ouput operations are
performed. A stream can basically be represented as a source or destination of characters of
indefinite length.
OR
Streams are generally associated to a physical source or destination of characters, like a disk
file, the keyboard, or the console, so the characters gotten or written to/from our abstraction
called stream are physically input/output to the physical device. For example, file streams are
C++ objects to manipulate and interact with files; Once a file stream is used to open a file,
any input or output operation performed on that stream is physically reflected in the file.
To operate with streams, C++ provides the standard iostream library, which contains the
following elements:
This is a set of class templates, each one having two template parameters: the char
type (charT) parameter, that determines the type of elements that are going to be
manipulated and the traits parameter, that provides additional characteristics specific
for a particular type of elements.
The class templates in this class hierarchy have the same name as their char-type
instantiations but with the prefix basic_. For example, the class template
which istream is instantiated from is called basic_istream, the one from
which fstream is is called basic_fstream, and so on... The only exception
is ios_base, which is by itself type-independent, and therefore is not based on a
template, but is a regular class.
The narrow-oriented (char type) instantiation is probably the better known part of the
iostream library. Classes like ios,istream and ofstream are narrow-oriented.
The classes of the wide-oriented (wchar_t) instatiation follow the same naming
conventions as the narrow-oriented instantiation but with the name of each class and
object prefixed with a w character, forming wios, wistream and wofstream, as an
example.
Standard objects
As part of the iostream library, the header file <iostream> declares certain objects
that are used to perform input and output operations on the standard input and
output.
They are divided in two sets: narrow-oriented objects, which are the
popular cin, cout, cerr and clog and their wide-oriented counterparts, declared
as wcin, wcout, wcerr and wclog.
Types
The iostream classes barely use fundamental types on their member's prototypes.
They generally use defined types that depend on the traits used in their instantiation.
For the default char and wchar_t instantiations,
types streampos, streamoffand streamsize are used to represent positions,
offsets and sizes, respectively.
Stream manipulators
Manipulators are functions specifically designed to be used in conjunction with the insertion
(<<) and extraction (>>) operators on stream objects, for example:
cout << boolalpha;
They are still regular functions and can also be called as any other function using a stream
object as argument, for example:
boolalpha (cout);
Manipulators are used to change formatting parameters on streams and to insert or extract
certain special characters.
Compatibility notes
The names, prototypes and examples included in this reference for the iostream classes
mostly describe and use the charinstantiations of the class templates instead of the templates
themselves, even though these classes are only one of their possible instantiations. We believe
this provides a better readability and is arguably as easy to obtain the names and prototypes
of the basic template from the char instantiation as the opposite.
ios_base Base class with type-independent members for the standard stream classes (class)
ios Base class with type-dependent members for the standard stream classes (class)
istream Input stream (class)
ostream Output Stream (class)
iostream Input/Output Stream (class)
ifstream Input file stream class (class)
ofstream Output file stream (class)
fstream Input/output file stream class (class)
istringstream Input string stream class (class)
ostringstream Output string stream class (class)
stringstream Input/output string stream class (class)
streambuf Base buffer class for streams (class)
filebuf File stream buffer (class)
stringbuf String stream buffer (class)
Objects:
Types:
Manipulators: