[IOSTREAMS] Forcing a flush on newlines

Hi! I'm outputting the progress from an externally executed command line application using the windows API call OutputDebugString. This means that I need to convert all line breaking characters to flush commands to make sure the text is outputted when a new line is received rather than when some underlying structure finds it suitable to linebreak. I've created a sink that writes to OutputDebugString and it works great, however unless I manually insert lots of std::endl (or flushing some other way) I won't get any output until the buffer is full. Is it possible to write an iostream filter that forces a flush on newlines or is this something I need to handle before feeding data into my stream? /David

David Larsson wrote:
Is it possible to write an iostream filter that forces a flush on newlines or is this something I need to handle before feeding data into my stream?
Hi, such a filter should work. I did not actually test it, but I inserted a boost::iostream::flush(sink); to one of my output filters and it compiles. Code is attached. Regards, Roland PS: The whole class is not very well tested, since we always use its input filter equivalent, but it should give you a start...
participants (2)
-
David Larsson
-
Roland Bock