1. Discussion
To prevent mojibake
may use a native Unicode API when writing to
a terminal bypassing the stream buffer. During the review of [P2093] "Formatted output" Tim Song suggested that synchronizing
with the
underlying stream may be beneficial for gradual adoption. This paper briefly
discusses this option.
Consider the following example:
printf ( "first \n " ); std :: ( "second \n " );
This will produce the expected output:
first second
because
is line buffered by default.
However, this may reorder the output:
printf ( "first" ); std :: ( "second" );
because of buffering in
but not
.
It is possible to prevent reordering by flushing the buffer before writing to a
terminal in
making this case less surprising. This will incur
additional cost but only for the terminal case and when transcoding is needed.
Neither {fmt} ([FMT]) nor Rust ([RUST-STDIO]) do such synchronization in
their implementations of
.