C++ Program to Display the Numbers Entered by User

In this program, you will learn to get the input from user and display them on console.
Here we have used cin and cout statements.

The C++ cout statement is the instance of the ostream class. It is used to produce output on the standard output device which is usually the display screen which is inserted in the standard output stream (cout) using the insertion operator(<<).

The C++ cin statement is the instance of the class istream and is used to read input from the standard input device which is usually a keyboard. The extraction operator(>>) is used along with the object cin for reading inputs. The extraction operator extracts the data from the object cin which is entered using the keyboard.

We have to include “iostream.h” file as shown in below C++ program to make use of these cin and cout statements in C++ language.



Source Code
#include<iostream>
using namespace std;


int main()
{
    int num1, num2;
    cout<<"Enter 2 numbers: ";
    cin>>num1>>num2;
    cout<<"The numbers are "<<num1<<" and "<<num2;
    return 0;
}
Output
Enter 2 numbers: 45 56
The numbers are 45 and 56