Custom output stream

D

Derek

From reading countless posts here I seem to get the impression that to
roll your own output stream class, the minimum you would likely needed
to do would be to override the overflow() method, as it is apparently
the default action of sync() is to call overflow(EOF).

In my own testing under Linux with g++, it appears that it is the
sync() method that needs to be overridden, as it does not appear to
default to calling overflow(EOF)... but overflow() certainly appears to
default in calling sync() when it needs more room.

Is this a "bug" with g++, or have I been mistaken in my intepretation
of the general consensus here?
 
B

Bo Persson

Derek said:
roll your own output stream class, the minimum you would likely
needed
to do would be to override the overflow() method, as it is
apparently
the default action of sync() is to call overflow(EOF).

That is for basic_filebuf, but not for basic_streambuf. The filebuf is
possibly buffered, so it might need a sync() to force the buffer out
(to disk perhaps?).

Other streams might not be buffered.
In my own testing under Linux with g++, it appears that it is the
sync() method that needs to be overridden, as it does not appear to
default to calling overflow(EOF)... but overflow() certainly appears
to
default in calling sync() when it needs more room.

At what level are you overriding?

In basic_streambuf, the default sync() does nothing, and overflow()
returns eof immediately. You must override whatever virtual functions
you need, to implement your special stream buffer. Exactly which ones
depends on what you are interfacing to.
Is this a "bug" with g++, or have I been mistaken in my
intepretation
of the general consensus here?

Not really.


Bo Persson
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top