0

In Turbo C++:

while(i<10)
{delay(100);
cout<<"*";
i++;}

will print "*" after a regular intervals of 100 milliseconds. If I try to do the same in C++ in UNIX like:

while(i<10)
{
sleep(1);
cout<<"*";
i++;}

it prints "*" 10 times after a single interval of 10 seconds at once.

Please, can someone explain why is it not working.

Ryan K
  • 3,985
  • 4
  • 39
  • 42
Saurav
  • 15
  • 6

1 Answers1

0

Because cout is often buffered by default. If you want it printed immediately, flush it:

std::cout << "*" << std::flush;
Dark Falcon
  • 43,592
  • 5
  • 83
  • 98