-1

I am currently giving codechef long challenge and there they are asking to flush the output after printing each line. How to use flush in cpp and how does this affect the time limit if I am not using flush? Currently I am using this code-

cout<<z<<" "<<endl;
cout.flush();

1 Answers1

3

Flushing makes output slower, because it cannot buffer 2 lines and output them at once.

However, std::endl already flushes for you.

You can send an endline without flushing by printing '\n'.

As an aside, you might want to std::ios_base::sync_with_stdio(false); to improve io speed if you aren't using C based IO.

Yakk - Adam Nevraumont
  • 262,606
  • 27
  • 330
  • 524