Getting Started with C++

Use of I/O Operators

In C++, one of the computer languages, the use of the stream insertion operator “<<”  takes place for output and the use of extraction operator “>>”  takes place for input. So, the use of I/O operators in C++ helps to take input and display output. Also, the operator whose use takes place to take the input is called the extraction or get from operator (>>), while the operator that is used for displaying the output is called the insertion or put to operator (<<).

Use of I/O operators

                                                                                                                                         Use of I/O Operators

Input Operator

The use of the input operator, commonly known as the extraction operator (>>), takes place with the standard input stream, cin. Furthermore, the treatment of the data takes place as a stream of characters by cin. Moreover, the flow of these characters takes place from cin to the program through the input operator.

Also, the working of the input operator is on two operands, namely, a variable on its right and the c in stream on its left. Therefore, the value is extracted or taken by the input operator through cin and its storing is in the variable.

Consider the example below to understand the concept of an input operator in C++. Moreover, this example will help in understanding the use of I/O operators.

A program that would demonstrate the working of an input operator.

                    

#include

Furthermore, using namespace, std;

int main () {

int a;

cin>>a;

a = a+1;

Finally, return 0;

}

Furthermore, in this example, an input from the user is taken by the statement cin>>. Afterwards, its storing takes place in the variable a.

Browse more Topics Under Getting Started with C++

Output Operator

The output operator is also known as the insertion operator (<<). Here, the treatment of data takes place as a stream of characters by cout. Furthermore, the flow of these characters takes place from the program to cout through the output operator.

The working of the output operator takes place on two operands, namely, the expression whose display is to be on its right and the cout stream on its left. Moreover, the value is directed or inserted to cout by the output operator.

Consider the example below in order to understand the concept of output operator. This in turn would help in understanding the use of I/O operators.

A program that would demonstrate the working of an output operator.

                    

#include

Furthermore, using namespace std;

int main () {

So, int a;

cin>>a;

a=a+1;

cout<<a;

Finally, return 0;

}

Cascading of Input/Output Operators

The cascading of the input and output operators refers to the consecutive occurrence of input or output operators in a single statement. To understand the concept of cascading of the input/output operator, two examples below must certainly be considered. These examples would certainly help in further understanding the use of I/O operators.

A program without cascading of the input/output operator:

                    

#include

Furthermore, using namespace std;

Moreover, int main () {

So, the next step is int a, b;

Furthermore, cin>>a;

cin>>b;

cout<<"The value of a is";

cout<<a;

Furthermore, cout<<"The value of b is";

cout<<b;

Finally, return 0;

}

A program with cascading of the input/output operator:

                    

#include

using namespace std;

So, the next step is-  int main () {

Moreover, int a, b;

cin>>a>>b;

cout<<"The value of b is : "<<b;

cout<<"The value of a is "<<a;

Finally, return 0;

}

FAQs For Use of I/O Operators 

Question 1: Differentiate between formatted and unformatted I/O operations in C++?

Answer 1: Formatted I/O functions allows the supplying of input or display of output in user desired format. In contrast, the unformatted I/O functions happen to be the most basic form of input and output. Moreover, there is no supplying of input or display of output in user desired format with the unformatted I/O functions.

Question 2: What is meant by C++ manipulators?

Answer 2: In C++, a programming language, manipulators refer to functions whose design is such that their use takes place in conjunction with the insertion (<<) and extraction (>>) operators on stream objects. Furthermore, the use of manipulators takes place to change formatting parameters on streams and for insertion or extraction of certain special characters. Understanding manipulators would certainly help in understanding the use of I/O operators.

Share with friends

Customize your course in 30 seconds

Which class are you in?
5th
6th
7th
8th
9th
10th
11th
12th
Get ready for all-new Live Classes!
Now learn Live with India's best teachers. Join courses with the best schedule and enjoy fun and interactive classes.
tutor
tutor
Ashhar Firdausi
IIT Roorkee
Biology
tutor
tutor
Dr. Nazma Shaik
VTU
Chemistry
tutor
tutor
Gaurav Tiwari
APJAKTU
Physics
Get Started

Leave a Reply

Your email address will not be published. Required fields are marked *

Download the App

Watch lectures, practise questions and take tests on the go.

Customize your course in 30 seconds

No thanks.