User Program Communication

User Input in C++

Used to receive input (int, word, byte, etc.) from the user using the header file.


Syntax
cin >> Variable; //input is stored to a variable

Notes

>> takes input from cin, which is the standard input stream.

Inputs can only be variables to store the inputted data.
Input data comes from the console.

cin is part of the std namespace. This means that you must either use std::cin if the namespace isn't used.


Example
using namespace std;

int inputData; 
cout << "Enter your age: "; 
cin >> inputData; 
cout << "Your age is: " << inputData << " years."; //Output is: Your age is (user input) years.

See Also
Documentation

Basic Input/Output - C++ Reference

Add to Slack

< Output   |   Commenting >

© 2018 SyntaxDB. All Rights Reserved.