Discuss briefly on predefined C++ streams

Estudies4you

 Q18. Discuss briefly on predefined C++ streams. Illustrate with the help of an example program.

Answer:
Predefined Streams
Predefined streams are those streams that are embedded in the system by default. These streams get activated, when the program execution starts.
The multiple predefined streams that are available in C++ are,
(a) cin
(b) cout
(c) cerr
(d) clog.

(a) cin
cin is an input object, which takes input through standard input device, keyboard. It is as similar to stdin in C. It uses extraction operator >> to read data.

(b) cout
cout is an output object, which gives output to standard output device i.e., monitor. It is as similar to stdout in C, It uses insertion operator << to display data.

(c) cerr
cerr is a standard error object, which is used to manage the errors in unbuffered data. This object passes the errors that are occurred in unbuffered data to standard output device i.e., monitor. Its functionality is similar to stderr in C.

(d) clog
clog is often a standard error object, but it manages the errors that takes place in buffered data. This type of pre defined stream is not supported by C.

Example
#include<iostream.h>
#include<conio.h>
int main()
{
clrscr();
cout<<“\n The cout displays normal output statements”;
clog<< “\n The clog displays errors of buffered data”;
cerr<<“\n The cerr displays unbuffered errors”;
getch();
return 0;
}

Output
Predefined Streams in C++

The above program executes predefined streams and controls the errors that are occurred in buffered and unbuffered data. The error messages are displayed on the screen.

To Top