Cout (Output stream)
For printing the statement to the screen the cout output stream is used .
Cout is the instant of the iostream class.
For Formatted output operation, cout is used .
The cout is used together with the insertion operator which is written as << (two less than opeartor together).
syntax :-. cout<< statement ;
cout<< “technical seek”;.
It prints technical seek statement to the output screen.
cout << 50;
It prints 50 value to output screen.
cout << x;
It prints the value of the variable x to output screen.
The insertion operator << inserts the data that follows it into the stream.in above example the technical seek, 50 and value of x is inserted into the cout Output stream.
We also see that in first example we written in double quotes and in 3rd example we written x . When the text is enclosed between quotes ,the text is printed literally. When not then text is interpreted as identifier of a variable, and it’s value is printed instead.
cout << ” technical”;
It prints the technical to output screen.
cout << technical;
It prints the value of technical variable.
Multiple insertion operator << used to chain the statement.
cout << “learn”<< “at” <<“technicalseek”<<“site”;
This will print as , learn at technicalseek site
Usually multiple insertion operator (chaining) used to mix the literals and variable.
cout <<” the value is “<<10;
This will print , the value is 10
Program to demonstrate output stream (cout function) in c++
void main ()
int no ;
no = 10;
cout <<" Output stream";. // cout for printing to output screen
// Print string literal using multiple insertion operator
cout << "learn cout "<<"output stream at"<<" technicalseek site";
cout<<" the value = "<<no;
learn cout output stream at technicalseek site
the value = 10
- In above program we print string literal and variable to output screen.
- We write simple string literal using cout<<“output stream “;
- Using multiple insertion operator<< we write the second cout
- Next we print the value of the variable no .