These member types are inherited from its base classes ostream and iosbase: event Type to indicate event type (public member type ) eventcallback Event callback function type (public member type ) failure Base class for stream exceptions (public member class ) fmtflags Type for stream format flags (public member type ) Init. To define the ostream class in C sources, the ostream header file must be included. To use the predefined ostream objects (std::cin, std::cout etc.) the header file must be included. 6.4.1.1: Writing to `ostream' objects The class ostream.
-->Defines the class template basic_ostream, which mediates insertions for the iostreams. The header also defines several related manipulators. (This header is typically included for you by another of the iostreams headers. You rarely need to include it directly.)
Syntax
Typedefs
Type name | Description |
---|---|
ostream | Creates a type from basic_ostream that is specialized on char and char_traits specialized on char . |
wostream | Creates a type from basic_ostream that is specialized on wchar_t and char_traits specialized on wchar_t . |
Manipulators
Name | Description |
---|---|
endl | Terminates a line and flushes the buffer. |
ends | Terminates a string. |
flush | Flushes the buffer. |
swap | Exchanges the values of the left basic_ostream object parameter for those of the right basic_ostream object parameter. |
Operators
Operator | Description |
---|---|
operator<< | Writes various types to the stream. |
Classes
C%2b%2b Ostream Dev Null
Class | Description |
---|---|
basic_ostream | The class template describes an object that controls insertion of elements and encoded objects into a stream buffer. |
See also
Header Files Reference
Thread Safety in the C++ Standard Library
iostream Programming
iostreams Conventions
C 2b 2b Ostream Dev Null Command
toton napsal:This would work on unices, but it is platform-specific.>Hi,
I want to have a log stream, where I can put certain logs. The log
can be console or file or any other ui widget.
This part I had already done with. However I want log stream
(std::ostream type) to initialize to a default null stream, when it is
not explicitly set to other stream, which will consume all of the
characters, like /dev/null .
How to write such a stream, derived from basic_ostream ?
Use ordinary std::fstream, open it only for writing to required file
'/dev/null'. It should work.
If you really want to create own stream, just derive it fromThis would be better, as it is not platform specific.
basic_ostream and simply define your own operator<< to be function
which only returns stream reference. You will have to write dummy
'write' and 'put' method too (and all other methods for output).
However, my suggestion would be to subclass std::streambuf to ignore any
characters written. Then the log stream can start out with the 'null'
streambuf, but be provided with a different one when logging is desired.
--
Nate