1

As much as I know, we do not get output to the screen from cout, until:

1.Buffer is full

2.Buffer is flushed

3.Program is terminated

So i have written following Code:

for(;;)
{
cout << "a";
_sleep(1000);
}

Compiler:clang++

Also tested on g++

OS: Windows 11

Every second I get an output? Why and how?

2
  • 3
    Maybe the buffer has size 1. Actually I believe the 3 points are the times you are guaranteed to see output, but nothing states that you won't see output before that. Commented Aug 21, 2022 at 10:20
  • Cannot reproduce on Windows (atm no linux available to test there as well) – using std::this_thread::sleep_for or windows Sleep both result in the behaviour you expect. Might be OS or compiler specific, you should add this information. Commented Aug 21, 2022 at 10:21

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.