c++ioiostreamcstdio

std::ios_base::sync_with_stdio(false), advantages, disadvantages?


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?

Solution

  • 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);