cin is a stream object in C used to read data from standard input. Usage: 1. Include the header file #include <iostream>; 2. Declare the cin object std::cin; 3. Use the >> operator to read the input; 4. Press the Enter key to submit the input, and the input will be stored in in the specified variable.
Using cin in C
What is Cin?
cin is a stream object in the C standard library used to read data from standard input (usually the keyboard).
Usage:
1. Include the header file
#include <iostream>
2. Declare the cin object
std::cin; // 声明 cin 对象
3. Use the >> operator to read the input
int num; std::cin >> num;
4. Press Enter to submit the input
After pressing the Enter key, the input will be read from the standard input and stored in the specified variable.
For example:
int main() { int num; std::cout << "Enter a number: "; std::cin >> num; std::cout << "The number is: " << num << std::endl; return 0; }
Note:
std::cin.ignore()
function. The above is the detailed content of How to use cin in c++. For more information, please follow other related articles on the PHP Chinese website!