Table of Contents
Previous Section Next Section

The I/O Operators

In C++, the << and the >> are overloaded to perform I/O operations. When used in an expression in which the left operand is a stream, the >> is an input operator and the << is an output operator. In the language of C++, the >> is called an extractor because it extracts data from the input stream. The << is called an inserter because it inserts data into the output stream. The general forms of these operators are shown here:

input-stream >> variable;
output-stream << expression

For example, the following fragment inputs two integer variables:

int i, j;
cin >> i >> j;

The following statement displays “This is a test 10 20”:

cout << "This is a test " << 10 << << ' ' << 4*5;

The I/O operators are not supported by C.


Table of Contents
Previous Section Next Section