It is considered bad form to use C and C ++ stream reading functions in one program. Nevertheless, this has never led to errors before.

Quite recently, solving a problem in which you need to consistently read int and char[] encountered this situation. If we read:

  1. int via scanf , and char[] via cin
  2. int via cin , and char[] via scanf

then this leads to the wrong answer. If both parameters are read by the same function, then the solution passes.

Therefore, the question arose: in what situations are possible conflicts between these functions.

    1 answer 1

    Most likely, you are doing something wrong. By default, the C and C ++ input and output libraries are synchronized, so it is safe to alternate the use of functions from one and another library. Synchronization can be enabled / disabled explicitly using the std::ios_base::sync_with_stdio .

    • Yes, thank you! My synchronization was turned off in order to increase the speed of cin'a. - slipstak2 Nov.
    • > My synchronization was turned off in order to increase the speed of cin'a. I wonder why cin'u speed? The user enters the data in a million times longer than the time required for their processing cin'om. - gammaker
    • 3
      and if the redirection of data from the file? for grep utilities. - KoVadim Nov.
    • GLMonster: Any data can go through the pipe - dzhioev