C++ output operator
causes the string in quotation marks to be display on the screen. this statement introduces two new c++ features,cout and << the identifier cout is a predefined object that represent the standard output stream in c++
Here the standard output stream represent the screen.
it is also possible to redirect the output to other output devices.
and the operator << is called the insertion or put to operator. it inserts(or sends) the contents of the variable on its right to the object on its left
The object cout has a simple interface. if string represent a string variable, then the following statement will display its contents:
cou << string;
you can be call that the operator << is bitwise left-shift operator and it can still be used for this purpose. this is an example of how one operator can be used for different works.
so we can also say this concept is know as opearator overloading.
in the c language we use printf() function for displaying string on screen.
1. In C++ input output operation is using the stream concept. Stream is the flow of data or sequence of bytes.
It makes the performance fast.
2. If the bytes flows from main memory to device like display screen, network connection, printer, etc,
this is known as output operation.
3. If the bytes flows from device like display screen, network connection, printer etc
to the main memory, this is known as input operation.
I/O Library Header Files
Let us see the common header files used in C++ programming are:
Header File |
Function and Description |
< iostream > |
It is used to define the cout, cin and cerr objects, which correspond to standard output stream, standard input stream and standard error stream, respectively |
< iomanip > |
It is used to declare services useful for performing formatted I/O, such as setprecision and setw. |
< fstream > |
It is used to declare services for user-controlled file processing. |
Standard output stream (cout)
The cout is a predefined object of class ostream . This is connected with the standard output device,
which is usually a display screen. The cout operator is used in conjunction with the (<<) stream insertion operator to show the output on a console.
Let’s see the simple example of standard output stream (cout):
using namespace std;
int main( ) {
char arr[] = "Welcome to programmingknow tutorial";
cout << "Value of char arr is: " << arr << endl;
}
|
Value of char arr is: Welcome to programmingknow tutorial
|