Input/Output Operators

Input/Output operators are helpful when user input values from an input device and output will be shown using output device.

Output operator "<<" : The output operator ("put to") is used to direct values to standard output.
For instance,
cout<<"Hello";  //String value
cout<<"World";  //String value

The above statement will produce the following output:
Hello World

Input Operator ">>": The output operator ("get from") is used to get a value from standard input.

eg: Program to read two integers and print addition of them.

void main()
    int a;
    int b;
    cout<<"Enter integer a = ";
    cout<<"Enter integer b = ";
    cout<<"Addition of a and b = ";

Output :
Enter integer a = 5
Enter integer b = 15;
Addition of a and b =20

Cascading of Input/Output Operators

The multiple use of input(">>") or output("<<") operators in a statement is called cascading of Input/Output operators.

The Input and Output operators can be concatenated as shown below:
cout<<"Enter four numbers: ";
cout<<"Numbers are :"

Enter four numbers:4 5 80 12
Numbers are : 4 5 80 12

Post a comment