[iostreams]howto replace ostream buffer?

How can one use iostreams::filtering_streambuf to replace the std::basic_streambuf used by cout. I've tried the code in 1st attachment; however, that code produces the output in 2nd attachment. The desired output is shown in 3ird attachment. How should the code be modified to get the desired output? TIA. -regards, Larry Hello World! is_complete=1 3ird Hello! Hello World! is_complete=1 2ND HELLO! 3ird Hello!

AMDG Larry Evans wrote:
How can one use iostreams::filtering_streambuf to replace the std::basic_streambuf used by cout. I've tried the code in 1st attachment; however, that code produces the output in 2nd attachment. The desired output is shown in 3ird attachment.
How should the code be modified to get the desired output?
Try flushing the stream before switching back to the original buffer. In Christ, Steven Watanabe

On 01/10/09 12:53, Steven Watanabe wrote:
AMDG
Larry Evans wrote:
How can one use iostreams::filtering_streambuf to replace the std::basic_streambuf used by cout. I've tried the code in 1st attachment; however, that code produces the output in 2nd attachment. The desired output is shown in 3ird attachment.
How should the code be modified to get the desired output?
Try flushing the stream before switching back to the original buffer.
Thanks. That works.

On 01/10/09 16:38, Larry Evans wrote:
On 01/10/09 12:53, Steven Watanabe wrote:
AMDG
Larry Evans wrote:
How can one use iostreams::filtering_streambuf to replace the std::basic_streambuf used by cout. I've tried the code in 1st attachment; however, that code produces the output in 2nd attachment. The desired output is shown in 3ird attachment.
How should the code be modified to get the desired output?
Try flushing the stream before switching back to the original buffer.
Thanks. That works. Another method is to use this:
this->push(my_filter,0,0); instead of: this->push(my_filter); I'm guessing that creates a non-buffered streambuf or something similar corresponding to my_filter, which makes the flush unnecessary.
participants (2)
-
Larry Evans
-
Steven Watanabe