While cout is used to output data to the screen, cin is used to get user input from the keyboard.
cin stands for "character input". It is used with the extraction operator >>.
#include <iostream> using namespace std;int main() { int age; cout << "Enter your age: "; cin >> age; // Get user input from the keyboard cout << "Your age is: " << age; return 0; }
In the example above, the program waits for the user to type a number and press Enter. The entered number is then stored in the age variable.
You can also chain the >> operator to take multiple inputs at once:
int x, y; cout << "Enter two numbers separated by space: "; cin >> x >> y; cout << "Sum: " << (x + y);
User input makes your applications dynamic and interactive!
Which operator is used with cin to extract input from the keyboard?