Preview
cin statement in C++ | Read input in C++
cin stands for console input. cin statement in C++ is used to read input from keyboard. cin is an instance of the istream
It can be used to read value of a variable.
It is followed by extraction operator (>>) followed by a variable whose value you want to read.
The header file required is <iostream>. You also need to use std namespace use cin statement.
Syntax:
cin>>val;
Here, val refers to the variable whose value you want to read .
//Program to demonstrate the use of cin statement.
#include<iostream> using namespace std; int main() { int i; double d; char c; cout<<"Enter an int value="; cin>>i; cout<<"Enter a double value="; cin>>d; cout<<"Enter a char value="; cin>>c; cout<<"\nint value="<<i; cout<<"\ndouble value="<<d; cout<<"\nchar value="<<c; return 0; }
Output
Enter an int value=45 Enter a double type value=5.85 Enter a character value=* int value=455 double value=5.85 char value=*
Popular Books of Computer Science