I have a function which works with a std::ostream
. I need to support using a C file handle (FILE*
). Should I be creating my own subclass of std::ostream
which delegates to a FILE*
?
I have a function which works with a std::ostream
. I need to support using a C file handle (FILE*
). Should I be creating my own subclass of std::ostream
which delegates to a FILE*
?
No, ostream
is not meant to be derived from. The way the iostreams library allows customization is by supplying a streambuf
pointer when creating an ostream
. streambuf
has a lot of virtual functions so you can change its behavior.
You need to derive either directly from streambuf
or from the existing filebuf
subclass. You probably only need to provide the overflow
function, the defaults for all the others should work ok.