Home > Article > Backend Development > What is cin in c++
cin is an input stream object in the C standard library, used to read data from the standard input (keyboard). Its syntax is: std::cin >> variable; can read different types of data, Such as integer, floating point number or string. cin will extract data until a whitespace character or end of file is encountered and store it in the specified variable. If the data types do not match, cin fails with the failbit set; use std::cin.fail() to check the failure status, and std::cin.ignore() to clear the input buffer.
cin in C
cin is an input stream in the C standard library Object that allows data to be read from the standard input device (usually the keyboard). It is the most common way to read data from the standard input stream std::cin
.
Syntax:
<code class="cpp">std::cin >> variable;</code>
Usage:
variable
can be any data type (Such as int
, float
, char
or string
).
Operator is used to extract data from the input stream and store it in a variable. cin
will fail with its failbit
bit set. Example:
Read an integer:
<code class="cpp">int num; std::cin >> num;</code>
Read a floating point number:
<code class="cpp">float value; std::cin >> value;</code>
Note:
cin
Reads data from standard input, so it is affected by the system environment, such as redirections or pipes. cin
will fail. In this case, the failure status can be checked using the std::cin.fail()
function. std::cin.ignore()
function to clear the remaining characters in the input buffer to avoid read errors. The above is the detailed content of What is cin in c++. For more information, please follow other related articles on the PHP Chinese website!