Input in C++
Last Updated :
01 Feb, 2021
The cin object in C++ is used to accept the input from the standard input device i.e., keyboard. it is the instance of the class istream. It is associated with the standard C input stream stdin. The extraction operator(>>) is used along with the object cin for reading inputs. The extraction operator extracts the data from the object cin which is entered using the keyboard.
Program 1:
Below is the C++ program to implement cin object to take input from the user:
C++
#include <iostream>
using namespace std;
int main()
{
int i;
cin >> i;
cout << i;
return 0;
}
|
Input:
Output:
Note: Multiple inputs can also be taken using the extraction operators(>>) with cin.
Program 2:
Below is the C++ program to implement multiple inputs from the user:
C++
#include <iostream>
using namespace std;
int main()
{
string name;
int age;
cin >> name >> age;
cout << "Name : " << name << endl;
cout << "Age : " << age << endl;
return 0;
}
|
Input:
Output:
Like Article
Suggest improvement
Share your thoughts in the comments
Please Login to comment...