I learned the hard way about using endl at the end of a cout statement to flush the buffer. What I’m confused about is why endl is only necessary sometimes. Usually I can just do
cout << "test";
And it will display test. But in the middle of a long console program I’ll have a similar cout statement and nothing will display and the code won’t move on. Adding endl to the end fixes the problem by flushing the buffer and displaying the text. But what causes the buffer to be automatically flushed in the some cases and manually flushed in others? I can’t provide any sample code because I don’t know how to reproduce the problem, but I’m assuming most of you have seen this.
When the buffer reaches a certain length or the program terminates normally, the buffer is flushed.