Return to Topic Menu | Computer Science Main Page | MathBits.com | Terms of Use

Using cin >>

We have seen how the double arrows (<<) of the cout show that the information is going "out" to the monitor.  In a similar way, the double arrows (>>) of the cin (pronounced see-in) show characters flowing "into" the program.  The arrows point the way.
When using cin, it is always necessary to provide a variable to the right of the operator to receive the input.

Sample program:

// sample program for cin
#include <iostream.h>

int main(void)
{
     int fleas;
     cout << "How many fleas does your cat have?";
     cin >> fleas;
     cout << "Well, that's " << fleas << " fleas too many!! \n\n\n";

     return 0;
}

 
cin can accept more than one variable as follows:

cout << "Enter an integer and a decimal:";
cin >> integer >> decimal;

You would enter the values by typing on a single line and leaving a space between them, or by typing them on separate lines and hitting ENTER after each entry.

 

Return to Topic Menu | Computer Science Main Page | MathBits.com  | Terms of Use