Home > Article > Backend Development > What is the use of cin in c++
In C cin is used to read data from standard input (keyboard). Its usage includes: associated with the input source: cin.tie(&cout); reading data using operators according to the data type: integer: >> floating point: >> character: get() or getline() string : getline() Boolean value: >>
The purpose of cin in c
cin is the C standard An input stream object in the library used to read data from standard input (usually the keyboard).
Usage
The syntax of cin is as follows:
<code class="cpp">cin >> variable_name;</code>
Among them, variable_name
is the variable to read the data from.
How to use
When using cin to read data, you first need to associate the stream with the input source, usually through cin.tie(&cout). Then, use different operators to read data according to different data types, as shown in the following table:
Data type | Operator |
---|---|
Integer | >> |
Floating point number | >> |
Character | get() or getline() |
String | getline() |
Boolean value | >> |
For example, to read an integer from the keyboard and Stored in the variable num
, you can use the following code:
<code class="cpp">cin.tie(&cout); int num; cin >> num;</code>
Features
The above is the detailed content of What is the use of cin in c++. For more information, please follow other related articles on the PHP Chinese website!