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.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…