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.

#include<iostream.h>
void main()
{
    int a;
    int b;
   
    cout<<"Enter integer a = ";
    cin>>a;
   
    cout<<"Enter integer b = ";
    cin>>b;
   
    cout<<"Addition of a and b = ";
    cout<<a+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: ";
cin>>number1>>number2>>number3>>number4;
cout<<"Numbers are :"
cout<<number1<<nubmer2<<number3<<number4;

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

Post a comment

0 Comments