[m-users.] Coupling stdout and stderr

Julien Fischer jfischer at opturion.com
Wed Mar 15 14:12:28 AEDT 2023


Hi Volker,

On Mon, 13 Mar 2023, Volker Wysk wrote:

> In C++ (and Haskell, I think) there's a feature which causes stdout to be
> flushed before writing something to stderr. I'm not sure how this is called.
> This way, the output on both streams occurs in the right order. Arbitrary
> streams can be coupled that way.

In C++ you can tie an istream to an ostream using the tie() function. Is
that what you were thinking of? It wouldn't help in this case because
cerr and cout are both ostreams.

> I've looked through the io library, but couldn't find anything like that.
> When you have a lot of output on stdout and then output something on stderr,
> the order gets messed up. You have to manually flash stdout before writing
> to stderr.

You could probably write something using the stdlib's stream interface
that did that.

Julien.


More information about the users mailing list