The exact value of iostream synchronizes with ios_base :: sync_with_stdio

It just means what we are doing with the object, since cout is synchronized with stdout (and vice versa?). What does it mean? Is stdio also syncing with stdout?

+6
source share
3 answers

The default value used by std :: cout and stdio (e.g. printf) is standard, but this is not necessarily the case.

The output can always be redirected to another destination. Referring to this: http://www.tldp.org/LDP/abs/html/io-redirection.html

+2
source

If synchronization is turned off, in some cases C ++ threads will be faster.

By default, all standard C ++ streams are synchronized with their respective C streams.

Example:

#include <iostream> #include <cstdio> using namespace std; int main() { cout.sync_with_stdio(false); cout << "Hello\n"; printf("World\n"); cout << "...\n"; } 

Output:

 Hello ... World 

Changing true gives the default result. Output:

 Hello World ... 
+8
source

Per cppreference:

 Sets whether the standard C++ streams are synchronized to the standard C streams after each input/output operation. 
0
source

Source: https://habr.com/ru/post/950320/


All Articles