C++ Crashkurs
outputstream.h File Reference
This file contains the OutputStream. More...
#include "stringbuffer.h"
Include dependency graph for outputstream.h:
This graph shows which files directly or indirectly include this file:
Classes | |
class | OutputStream |
The class OutputStream corresponds, essentially, to the class ostream from the C++ IO-Stream library. More... | |
Functions | |
OutputStream & | flush (OutputStream &os) |
Enforces a buffer flush. More... | |
OutputStream & | endl (OutputStream &os) |
Prints a newline character to the stream and issues a buffer flush. More... | |
OutputStream & | bin (OutputStream &os) |
Print subsequent numbers in binary form. More... | |
OutputStream & | oct (OutputStream &os) |
Print subsequent numbers in octal form. More... | |
OutputStream & | dec (OutputStream &os) |
Print subsequent numbers in decimal form. More... | |
OutputStream & | hex (OutputStream &os) |
Print subsequent numbers in hex form. More... | |
Detailed Description
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 methodOutputStream& 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.
Function Documentation
OutputStream& flush | ( | OutputStream & | os | ) |
Enforces a buffer flush.
- Parameters
-
os Reference to stream to be flushed.
- Returns
- Reference to OutputStream os; allows operator chaining.
OutputStream& endl | ( | OutputStream & | os | ) |
Prints a newline character to the stream and issues a buffer flush.
- Parameters
-
os Reference to stream to be modified.
- Returns
- Reference to OutputStream os; allows operator chaining.
OutputStream& bin | ( | OutputStream & | os | ) |
Print subsequent numbers in binary form.
- Parameters
-
os Reference to stream to be modified.
- Returns
- Reference to OutputStream os; allows operator chaining.
OutputStream& oct | ( | OutputStream & | os | ) |
Print subsequent numbers in octal form.
- Parameters
-
os Reference to stream to be modified.
- Returns
- Reference to OutputStream os; allows operator chaining.
OutputStream& dec | ( | OutputStream & | os | ) |
Print subsequent numbers in decimal form.
- Parameters
-
os Reference to stream to be modified.
- Returns
- Reference to OutputStream os; allows operator chaining.
OutputStream& hex | ( | OutputStream & | os | ) |
Print subsequent numbers in hex form.
- Parameters
-
os Reference to stream to be modified.
- Returns
- Reference to OutputStream os; allows operator chaining.