Output stream : Cout is a Output stream in cpp programming.
For printing the statement to the screen the cout output stream is used .
Cout meaning : 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).
cout 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.
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 for output stream
using namespace std;
int no ;
no = 10;
cout <<" Output stream\n";// cout for printing to output screen
// Print string literal using multiple insertion operator
cout << "learn cout "<<" output stream at"<<" technicalseek site";
cout<<" \nThe value = "<<no;
1. In above program we print string literal and variable to output screen.
2. We write simple string literal using cout<<“output stream “;
3. Using multiple insertion operator<< we write the second cout
4. Next we print the value of the variable no .