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

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 (<<)

Syntax:

cout<<Variable/Constant/Expression;

Examples:

cout<<“C++ Programming”;

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

cout<<245;

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

cout<<price;

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

Output

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.

Syntax:

cin>>variable;

Examples:

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

cin>>a>>b>>c;

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

C++ Input simple Example

Latest posts by Prof. Fazal Rehman Shamil (see all)

Buy advertisement space on T4Tutorials

For more details email [email protected]