+ 2
Plz tell me how to use cin in C++
6 Respostas
+ 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;
+ 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.
+ 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.
+ 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)
+ 2
plz explain a little more
+ 2
what is the mean of cin>>a;