2.4. Type-Safe I/O

The C++ IOStream library handles input and output with the following.

#include <iostream.h> 

cin >> name;               // standard input
cout << name;              // standard output
cerr << name;              // standard error

The name cin (pronounced “see-in”) with stream operator >> reads values from standard input (your keyboard by default). The name cout (pronounced “see-out”) with stream operator << writes to standard output (your CRT screen by default). Likewise, the name cerr with stream operator << writes error messages to standard error (your CRT screen by default). You must include <iostream.h> to use these names and operators.

The stream names and operators are appealing because they are type safe and easy to use. More than one C++ variable may appear ...

Get Navigating C++ and Object-Oriented Design now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.