How to input/output in C++ (CPP, C Plus Plus)

By: Prof. Fazal Rehman Shamil
Last modified on October 3rd, 2019

How to input/output in C++ (CPP, C Plus Plus)

When you type at the keyboard and your program takes your input as data that is standard input. When your output is displayed at the terminal screen that is standard output. The standard input stream is called cin, The standard output stream is called cout.

To get basic I/O functionality, you must #include < iostream > library in header of C++ program. 

Standard Output

By default. the term standard output refers to the output display on the screen. C++ language uses the cout stream object to display standard display. The word ‘cout‘ stands for console output. The cout object is used with the insertion operator (<<)




cout<<“C++ Programming”;

The above line will display “C++ Programming” on the screen. The string constant is always enclosed in double quotes.


The above line will display 245 on the screen. The numeric constant is not enclosed in quotation marks.


The above line will display
the value of variable
a on the screen. The variable is not enclosed in quotation  marks;

cout<<“The Value of Price”<<price;

The above line will displays “The Value of Price” along with the value of variable Price on the screen. The insertion operator 

is used for twice to concatenate the string value with the value of Price.

C++ Output simple Example


Standard Input

By default, the term standard input refers to the input given vie keyboard. C++ language uses cin stream object to get standard input. The word ‘cin‘ stands for console input. C++ handles standard input by applying the extraction operator (>>) with cinstream. The operator must be followed by a variable. The variable is used to store the input data.




The above line will get a value from the keyboard and store it in variable y.


The above line will get three values from keyboard and store in variables a,b and c.

C++ Input simple Example

Prof. Fazal Rehman Shamil