0

What is the difference between std::ios_base::sync_with_stdio( false );
Vs std::cout.sync_with_stdio( false ); and std::cin.sync_with_stdio( false );?

Which one should I use supposing my code does not use any of the C streams from <cstdio> and only uses C++ streams from <iostream>?

I want to know:

  1. what are the advantages of disabling the synchronization?
  2. What can go wrong if synchronization is set to false? Which things should I take into account if I want to disable the synchronization?
digito_evo
  • 3,216
  • 2
  • 14
  • 42

1 Answers1

0

sync_with_stdio is a static function.

so

std::cout.sync_with_stdio(false);

is in fact

std::cout, std::ios_base::sync_with_stdio(false);
Jarod42
  • 203,559
  • 14
  • 181
  • 302
  • I don't understand the last line though. – digito_evo Dec 10 '21 at 10:20
  • `std::cout` is evaluated (and result discarded). It is basically equivalent to `std::ios_base::sync_with_stdio(false);`. – Jarod42 Dec 10 '21 at 10:26
  • So no difference? I thought `std::cout.sync_with_stdio(false);` only disables the synchronization for std::cout and `std::ios_base::sync_with_stdio(false);` disables synchronization for all the eight C++ stream objects. Isn't this true? – digito_evo Dec 10 '21 at 10:35
  • @digito_evo If you don't understand the expression containing a comma then you probably should read about the [built-in comma operator](https://en.cppreference.com/w/cpp/language/operator_other#Built-in_comma_operator) in C++. – heap underrun Dec 10 '21 at 10:39
  • @heap underrun Thanks for the link. Now I understand it. – digito_evo Dec 10 '21 at 10:53