Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

syncing iostream with stdio

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

like image 252
vehomzzz Avatar asked Dec 07 '22 05:12

vehomzzz


1 Answers

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).

like image 58
KeatsPeeks Avatar answered Dec 09 '22 18:12

KeatsPeeks