User Input

 

As we have already discussed earlier cin is used to get user input. This is paired along with the extraction operator (>>)

 

The following example reads a value from the user and prints it on the screen.

Example:

 

#include <iostream>
using namespace std;

int main()
{
  int num;
  cout << "Type a number: "; // displayed on the screen
  cin >> num; //value taken from User
  cout << "Your number is: " << num; // number displayed on the screen

  return 0;
}