<I>cin</I>: <I>cout</I>'s evil twin


Of course, if there's an out, there has to be an in, and if there's a cout, there has to be a cin. cin is another "black box" as we talked about earlier -- we don't know how it manages to read in from the keyboard, but it does, and we're thankful for it. cin is remarkably similar to cout, so let's just jump in and use it:

#include <iostream.h>

void main(void)
{
  int pepper;
  
  cin >> pepper;
}

Notice the >> operator? It is, obviously, the opposite of the << operator, in that it takes data from cin and assigns it to pepper. Since pepper is an int, cin will automatically convert whatever you type into an integer, if it can; if you type in something like "Nachos", don't expect it to be able to turn that into a number.


Table of Contents

Hello, World! | The Pre-Processor | Headers | cout: The Black Box
More Wonders of cout | cin: cout's evil twin | Exercises