I have implemented a stream that sends output to the debugger (using OutputDebugString() in Windows):
class debug_output_sink : public boost::iostreams::sink {
public:
debug_output_sink(int) { }
std::streamsize write(const char* s, std::streamsize n);
// also tried with:
// struct category : boost::iostreams::sink::category, boost::iostreams::flushable_tag { };
// bool flush() { return true; }
};
When I use it directly, flush() works fine:
stream_buffer<debug_output_sink> debug_streambuf(debug_sink);
ostream debug_stream(&debug_streambuf);
debug_stream << "test\n";
debug_stream.flush(); // characters appear immediately
However, when I put it in a filter, flushing the filter doesn't flush the stream:
// scope
{
stream_buffer<debug_output_sink> debug_streambuf(debug_sink);
ostream debug_stream(&debug_streambuf);
filtering_ostreambuf filtering_buf;
filtering_buf.push(debug_stream);
ostream os(&filtering_buf);
os << "test";
os.flush(); // nothing
filtering_buf.pubsync(); // nothing either
filtering_buf.strict_sync(); // still nothing
}
// characters appear at last !
What I am missing here?
Thanks,
Jean-Louis Leroy