C++ INPUT/OUTPUT

Estudies4you

C++ INPUT/OUTPUT

Q1. Define stream.
Answer:
A stream can be defined an interface between user and I/O devices. The I/O devices such as keyboard,disk, tape driver and monitor provides a source to perform I/O operations which include read and write operations. To perform I/O operations, I/O stream functions are mandatory and these functions are available in standard C++ library.
A standard library contains, .obj files and they are included in the program to perform various V/O operations. These operations provide portability to the program.
A stream can also be defined as flow of data. The flow can be calculated in terms of bytes in sequential manner, There are two types of streams, such as source stream and destination stream. The source stream receives data from the input devices such as keyboard and the data is considered as input data. Therefore, the other name for Source stream is given as input stream. On the otherhand, the destination stream collects data from the Program and passes to output devices such as monitor. Therefore, the other name of destination stream is output stream.

Q2. Write about stream class hierarchy.
Answer:
Stream classes are set of classes, whose functionality depends on console file operations. The stream classes are declared in header file “iostream.h”, It is mandatory for a programmer to include this header file, whenever a program is written using the functions supported by these stream classes.
Stream class hierarchy consists of,
(i) ios as the parent.class
(i) istreamostream as child classes
(iii) iostreambuffer as a member variable object of ios
(iv) The iostream class as a child class of both istream class and ostream class.

Q3. What are file stream classes?
Answer:
File streams are used to transfer data between Program and a disk file. Therefore, a file stream acts’as an interface between the programs and the files: The file stream I/O operations are similar to console stream I/O operations. The stream that Provides the data to the program is called as an input stream and the stream that is used to receive the data from the program is called as an output stream. An input stream is used to extract the data from a file and an output stream is used to insert the data to a file. Performing input operations on file stream requires creation of an input stream and linking it with the program and the input file. Similarly performing output operations on file streams requires establishment of an output stream with the necessary links with the program and the output file.

Q4. Discuss in brief about string streams.
Answer:
Hierarchy of string streams is as shown in the below figure,
Define stream,Write about stream class hierarchy,stream class hierarchy in c++,What are file stream classes in c++,explain string streams in c++,manipulators in c++,Define input stream and output stream in c++,overloading insertion and extraction operators in c++,What are the predefined streams in C++, explain ifstream class in c++,explain open() and close() function class in c++,
Figure: Hierarchy of String Streams

C++ provide the following classes to perform string streams i.e., I/O operations on string. These classes are’declared in the <stream.h> header file. These classes are,
(i) istringstream class
(ii) ostringstream class
(iii) stringstream class
(iv) stringbuf class.

Q5. Write in short about manipulators.
Answer: 
Manipulators are used for manipulating (controlling) the output formats. They are similar to that of ios class member functions and flags. The only difference is that, the ios class member function returns the previous settings, whereas, the manipulator does not return the previous setting.
Manipulator along with cout statement can be written as,
cout<<manip1<<manip2<<varl ;
Where,
manip1 manip2 are manipulators and varl is C++ variable.
To Top