< C++ Tutorial

C++ input & output

← Previous Next →

C++ uses a convenient abstraction called streams to perform input and output operations in sequential media such as the screen, the keyboard or a file. A stream is an entity where a program can either insert or extract characters to/from.

The standard library defines a handful of stream objects that can be used to access what are considered the standard sources and destinations of characters by the environment where the program runs:

Stream Description
cin standard input stream
cout standard output stream

Standard Output (cout):

int a = 20;
cout << "Hello George";
cout << 10;
cout<< a;

cout can be used to print constant string or values of variables, etc.

Multiple insertion operations can be used in a single statement.

cout << "My name" << " is" << "George." << endl << "I am a developer";

Note: endl is used to give a line break. "\n" can also be used for changing lines.

Standard Input (cin):

int age;
cin >> age;

cin can be used to input integers, float and strings

Multiple inputs can be made by single command:

cin >> age >> height;
← Previous Next →