In C language, the input and output operations are performed using built-in library functions such as printf() and scanf(). But, C++ uses a new method of standard input and output called I/O stream.
A stream is a bytes of characters from memory to display on screen or read from the keyboard to the computer memory. The C++ language uses cin
to read inputs from keyboard and cout
to display characters on a screen.
The I/O Stream Library
The C++ standard library is a repository for a C++ program to get the desired functions. The
Turbo C++ And Borland C++ IO Stream Files
Some other compilers uses extra stream files such as:
The stream library is nothing but a hierarchy of classes and functions for each class is defined. You will learn more about class in future lessons.
C++ I/O Stream Objects
The I/O stream objects are used to perform the input and output operations. They take arguments such as objects, variables, strings, and so on. Basically, all are characters to the stream so there is no conflict with respect to data type.
In C language, every input and output operation has a format specifier –
The C++ uses following objects for input and output.
- cout
- cin
- cerr
- clog
cout
The
cout << var 1 << var 2 << ...<< var n;
There are many ways to write output statement in C++.
For example,
cout << number << number 2 << number3 ;
cout << "Number =" << number ;
cout << number ;
cout << number2;
The
cin
The
The syntax for
cin >> var 1 >> var 2 >> var n;
The
cin >> number;
cin >> A >> B >> C;
The
cerr
It is used for reporting error and it has its
clog
The clog is slower and not written to the external device quickly, unless the buffer is full. It is also associated with
Summary of IO Streams
IO stream | Meaning | Associated files |
cout | standard output | stdout |
cin | standard input | stdin |
cerr | standard error reporting | stderr |
clog | standard log | stderr |