![]() |
VOOZH | about |
Input in C++ refers to the process of accepting data from the user or an external source so that a program can perform operations on that data. User input makes programs interactive and allows them to work with dynamic values instead of fixed data.
C++ provides several ways to accept input from the user. The most commonly used methods are:
The cin object is part of the <iostream> library and is used to read formatted input from the standard input device (usually the keyboard). It uses the extraction operator (>>) to read values and store them in variables.
Input:
10
Output:
10
Explanation:
The cin object can read multiple values in a single statement by chaining the extraction operator (>>).
Input:
ABC
10
Output:
Name : ABC
Age : 10
Explanation:
The getline() function is used to read an entire line of text, including spaces.
Input
John SmithOutput
John SmithExplanation:
The cin.get() function is used to read a single character from the input stream.
Input
AOutput
AExplanation: