0% found this document useful (0 votes)
26 views

C Insertion and Extraction Operator

The insertion (<<) and extraction (>>) operators in C++ are used to write information to and read information from ostream and istream objects like cout and cin respectively. The insertion operator cout is used to display output to the screen, similar to printf in C, while the extraction operator cin extracts input from the keyboard, similar to scanf in C. Both cout and cin require including the iostream.h header file.

Uploaded by

radhika borawake
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
26 views

C Insertion and Extraction Operator

The insertion (<<) and extraction (>>) operators in C++ are used to write information to and read information from ostream and istream objects like cout and cin respectively. The insertion operator cout is used to display output to the screen, similar to printf in C, while the extraction operator cin extracts input from the keyboard, similar to scanf in C. Both cout and cin require including the iostream.h header file.

Uploaded by

radhika borawake
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

C++ insertion(<<) and extraction(>>) Operators

The insertion and extraction operators are used to write information to or read information
to or read information from, respectively, ostream and istream objects.

By default, white space is skipped when the insertion and extraction operators are used.

The insertion operator << (Common Output - cout) :

The insertion operator ( << ) points to the ostream object wherein the information is inserted.
The normal associativity of the << -operator remains unaltered, so when a statement like :

cout << "hello" << "world";

is encountered, the leftmost two operands are evaluated first (cout << hello).

cout is an ostream object, into which information can be inserted. This stream is normally
connected to the screen.

cout << is used for displaying the message or a result of an expression.

It is same as of printf() function used in c language.

Syntax :

cout <<"Message to print'' or result to be show

Eg : cout << "Welcome to c++ ";

The extraction operator >> (Common Input- cin) :

cin is an istream object from which information can be extracted. This stream is normally
connected to the keyboard.

cin is used to insert the information or the value of a variable.

This works same as scanf() works in C language.


Syntax :

cin >> variable value;

Eg : cin >> x;

where x is a variable.

iostream.h header file :

To use cin >> and cout << we have to include the "iostream.h" header file in our program.
This header file contains the definition (prototype) of both cout and cin.

You might also like