Friday 18 March 2011

4. C++ I/O


1.) C++ I/O
C++ new features for handling I/O operations are called streams. Streams are abstraction that refer to data flow. Streams are classified into two types:
There are:
                   Output stream
                    Input stream

Output stream: The output stream allow us to perform write operations on output devices. Output on the standard stream is performed using the cout object

Syntax: cout<<variable;

Input stream: the input stream allow us to perform read operation. Input from the standard stream is performed using cin object.

Syntax: cin>>variable;

2) Hierarchy of stream classes:

The c++ input –output system supports a hierarchic of classes that are called stream classes.
Hierarchy of stream classes.




The iostream facility of C++ provides an easy means to perform I/O. the class istream uses predefined stream cin object that can be used to read data from standard input device (ex: keyboard) the extraction operator >> is used to get data from a stream. The insertion operator << is used to output data into a stream. The classes istream, ostream and iostream which are designed exclusively to manage the console, device are declared in the header file “iostream.h”. 

2) Explain about IOS CLASS:


It provides common to both input and output. It contains a pointer to a buffer object.
The classes derived from the ios class (istream, ostream, iostream) perform specialized input-output operations.

·        Istream does formatted input.
·        Ostream does formatted output.
·        IOstream does formatted input and output.

IStream class: It is derived class of IOstream and inherits the properties of IOS. It defined input functions such as get(), getline(), and read(). Stram extraction operator >> to read data from a standard input device to the memory items.

OStream class: it is a derived class of ios and hence, inherits the properties of IOS. It defines output functions such as put() and write(). Stream insertion operator <<.

IOstream class : It is derived from base classes istream and ostream which are inturn inherited from class ios. It provides facility for handling both input and output.Stream.

 
Explain I/O manipulators and give examples

No comments:

Post a Comment