+ 2

Plz tell me how to use cin in C++

27th Apr 2018, 4:23 PM
Lovenish Purohit
Lovenish Purohit - avatar
6 Answers
+ 10
Cin is used to get input from the user and store it in a variable. let's assume you have a variable 'a' of type 'int', then to get a integer input from the user and store it in 'a', you'll need to type, cin >> a;
27th Apr 2018, 6:57 PM
Rusty.Metal
+ 5
cin is short for common input (from keyboard), ">>" is called extraction operator (it extracts something from input stream). cin will read in every numeric character as one whole unit until there is a space or an end-of-line (\n or endl) and place it in the variable. Other input operators include cin.get(char); getline(cin, x);. Get is only for alpha char and getline does not pick up end of line. Everywhere you see cin, you can use your own input file stream variable, such as ifstream indatuh, to obtain data from an external file. ch = cin.peek(); can be used to see what the next char is without extracting it. Hope this is right & helps.
28th Apr 2018, 1:20 AM
Eric Zatarack
Eric Zatarack - avatar
+ 3
if you have a row of integers as a single number and want to take them one digit at a time you could read it in as a string array (with cin) and work on the digits individually with an index from 0 to end of number. if need be, you can convert digits to character with x=static_cast<char>(x), etc.
28th Apr 2018, 1:31 AM
Eric Zatarack
Eric Zatarack - avatar
+ 2
SIMPLE... int a; //Creates a variable named a cout<<"Enter a"; //print Enter a on screen cin>>a; //takes input from user cin takes value from user and gives to the given variable(here it is a)
27th Apr 2018, 4:29 PM
Biswajit patra
Biswajit patra - avatar
+ 2
plz explain a little more
27th Apr 2018, 4:30 PM
Lovenish Purohit
Lovenish Purohit - avatar
+ 2
what is the mean of cin>>a;
27th Apr 2018, 4:31 PM
Lovenish Purohit
Lovenish Purohit - avatar