I am trying to add iostream to the legacy code and thus want to sync those two libraries. According to this article, I should use std::ios_base::sync_with_stdio.
Now, I wonder how it is used in practice (examples please), side-effects I should be aware of.
Thx
By default the streams are synchronized, it's guaranteed to work by the standard, you don't have to do anything. sync_with_stdio
is only here to disable synchronisation if you want to.
From the article you mentioned :
For the predefined streams, it's safe to mix stdio and iostreams. For example, you can safely use stdin and cin in the same program; the C++ Standard guarantees that it will work the way you would naively expect it to.
The only drawback is a potential performance hit (I guess that's why it can be disabled).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With