Is this simply means whatever we do with object like cout gets in sync with stdout (and vice versa?). What does this exactly mean. Is stdio also sync with stdout?
If the synchronization is off, the C++ streams will be faster in some cases.
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 it to true
gives default result in order.
Output:
Hello
World
...
The default ostream used by std::cout and stdio(like printf) is stdout, but it is not necessarily so.
The output could alway be redirected to the other destination. Referencing this: http://www.tldp.org/LDP/abs/html/io-redirection.html
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