1

I have a few std::cout statements and few of them do not print output to console till program ends. But it i put getchar(), it starts printing output. Why does it happen, can someone please explain?

CuriousCase
  • 745
  • 2
  • 9
  • 22
  • Also see [Unbuffered output with cout](http://stackoverflow.com/questions/1377084/unbuffered-output-with-cout?rq=1) – Bo Persson Oct 28 '15 at 10:15

1 Answers1

3

The issue may be because you are not trying to flush your output. You can try like this:

std::cout << "some text" << std::flush;

or like

std::cout << "some text" << std::endl;

The standard output is buffered and on newline the buffer is flushed.

Rahul Tripathi
  • 168,305
  • 31
  • 280
  • 331
  • 2
    And standard output is also flushed when **standard input** is read, which is why `getchar()` works. – MSalters Oct 28 '15 at 13:11