Cascading of I/O Operators

C++ supports the use of stream extraction (>>) and stream insertion (<<) operator many times in a single input (cin) and output (cout) statements. If a program requires more than one input variable then it is possible to input these variables in a single cin statement using multiple stream extraction operators. Similarly, when we want to output more than one result then this can be done using a single cout statement with multiple stream insertion operators. This is called cascading of input output operators.
 Example:
cout<<”Enter the first number”;
cin>>a;
cout<<”Enter the second number”;
cin>>b;

 Instead of using cin statement twice, we can use a single cin statement and input the two numbers using multiple stream extraction operators.
cout<<”Enter the two number”;
cin>>a>>b;
Similarly, we can even output multiple results in a single cout statements using cascading of stream insertion operators.
cout<<”The sum of two number is”<<sum<<endl;


learn more
How to Create a Youtube Channel | Create your youtube channel in minutes...
Previous
Next Post »