Look this example:
#include <iostream>
#include <stdio.h>
int main()
{
std::ios::sync_with_stdio(false);
std::cout << "a";
printf("b");
std::cout << "c";
}
On gcc 9.2 I'm getting acb
as output. I was expecting bac
, because, if I understood correctly, std::cout
would be using its buffer. Why was it printed in this order?
Additional question: setting std::ios::sync_with_stdio(false)
would improve performance (in the above example, for instance)?