C%2b%2b Ostream Dev Null

C%2b%2b

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.

C%2b%2b-->

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

C%2b%2b Ostream Dev Null

Typedefs

NullDev
Type nameDescription
ostreamCreates a type from basic_ostream that is specialized on char and char_traits specialized on char.
wostreamCreates a type from basic_ostream that is specialized on wchar_t and char_traits specialized on wchar_t.

Manipulators

NameDescription
endlTerminates a line and flushes the buffer.
endsTerminates a string.
flushFlushes the buffer.
swapExchanges the values of the left basic_ostream object parameter for those of the right basic_ostream object parameter.

Operators

OperatorDescription
operator<<Writes various types to the stream.

Classes

C%2b%2b Ostream Dev Null

ClassDescription
basic_ostreamThe 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

Ondra Holub wrote:
toton napsal:
>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.
This would work on unices, but it is platform-specific.
If you really want to create own stream, just derive it from
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).
This would be better, as it is not platform specific.
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