Skip to main content

C++ : Cascading of I/O Operators

C++ : Cascading of I/O Operators 


Successive occurrence of operators (">>" or "<<" respectively) can be concatenated   

example 1 -

cout << "The sum of 2 + 5 = " << 2 +5 \n";

example 2 -

cout >> "The result of 8 - 2 is" << 8 -2;

example 3 -

cout << "the sum of" <<  value1 << "and" << "is" << value 1 + value2 << "\n";

example 4 -
Similarly successive occurrences of input operator (>>) can also be concatenated as follows :

 cout << " Enter two numbers :";

cin >> value1 >> value2;




Demo - ( squaring numbers)
#include <iostream>
using namespace std;

int main()
{
    int var, sqrs; cout << "enter number:\n"; cin >> var; sqrs = var * var; cout << "\nanswers\n" << sqrs << endl;


}

Result -


Without Cascading -