This file contains the OutputStream.
Along with the class OutputStream itself, this file contains definitions for the manipulators hex, dec, oct, and bin, which are used for changing the radix, and endl for signaling the end of the current line.
- Manipulators
- To simplify formatting text and numbers using the class OutputStream, we define so-called manipulators. For example, the expression
kout << "a = " << dec << a << " is hexadecimal " << hex << a << endl; should, at first, print the value stored in decimal and then in hexadecimal form, followed by a line break. The intended properties can be realized by implementing hex, dec, oct, bin, and endl as functions (i.e., they are, in particular, not methods of OutputStream) that take (as first parameter) and return a reference to an OutputStream object. When compiling the expression show above, the method OutputStream& OutputStream::operator<< ((f) (OutputStream&)) is chosen when one of the functions hex, dec, oct, bin, or endl is streamed an OutputStream, which finally will execute the passed function.
- Note
- The term manipulator originates from the book The C++ Programming Language by Bjarne Stroustrup. Refer to this book for further explanations.