Although these definitions come from a library, rather than being part of the core language,” they are sufficiently central to be specified in the latest draft standard for C++.
You can use two operators defined in this library for basic input and output operations. They are familiar from any C++ introductory text-book: << for output, and >> for input. (Think of data flowing in the direction of the “arrows.”)
These operators are often used in conjunction with the following three streams that are open by default.
#include <iostream.h>
int main(int argc, char **argv)
{
cout << "Well, hi there.\n";
return 0;
}
Casual use of these operators
may be seductive, but—other than in writing throwaway code for your own
use—it is not necessarily simpler than managing input and output in any
other language. For example, robust code should check the state of the
input and output streams between operations (for example, using the method,
good).
See also Checking the
state of a stream. You may also need to adjust maximum input or output
field widths, using manipulators like setw
or setprecision.
cout << "The value of i is " << i << "\n";>>
Returns a reference to the implied argument, *this (the open stream it reads), permitting multiple inputs in one statement.