C++ keyboard input
To take keyboard input in C++, follow these steps:
- Include the necessary header file for input/output operations:
#include <iostream>
- Use the std namespace to avoid writing
std::
before every input/output operation:
using namespace std;
- Declare variables to store the input:
int number;
string name;
- Use the
cin
object to receive input from the keyboard and store it in the variables:
cin >> number;
cin >> name;