C++, like C, has no built-in input or output statements. Instead, I/O facilities are provided by a library. The C++ compiler provides both the classic implementation and the ISO standard implementation of the iostream classes.
There are four predefined iostreams:
- cin, connected to standard input
- cout, connected to standard output
- cerr, connected to standard error
- clog, connected to standard error
By including the iostream library, a program can use any number of input or output streams. Each stream has some source or sink, which may be one of the following:
Standard output
Standard error
A file
An array of characters
Output Using iostream
- Output using iostream usually relies on the overloaded left-shift operator (<<) which, in the context of iostream, is called the insertion operator. To output a value to standard output, you insert the value in the predefined output stream cout. For example, given a value someValue, you send it to standard output with a statement like:
cout << someValue;
to write 2 values
cout << someValue << anotherValue;
with space? cont<<somevalue<<" "<<anothervalue