-1

I realize that the output is the same.
case 1:

cout << "enter password " <<flush;      

case 2:

cout << "enter password " <<endl;  
songyuanyao
  • 169,198
  • 16
  • 310
  • 405
Chris
  • 171
  • 1
  • 3
  • 11

2 Answers2

11

endl adds an end of line characters to the output before flushing the buffers. flush only flushes.

Serge
  • 11,616
  • 3
  • 18
  • 28
-1

cout is buffered. Text that goes into it might be held in memory until more text comes through, then it all goes out at the same time. This is more efficient but comes at the cost of not displaying all the text in its buffer sometimes.

I expect flush flushes the buffer so that all the text gets output right away.

I don't know whether flush also provides an end of line terminator.

Mike Crawford
  • 2,232
  • 2
  • 18
  • 28