Which C++ stream manipulator forces the output buffer to be flushed?
Options
- A. endl
- B. flush
- C. Both endl and flush
- D. More than one of the above
- E. None of the above
Quiz Practice:
C. Both endl and flush
Answer: (C) Both endl and flush
Both endl and flush can cause the output buffer to be flushed.
endl inserts a newline and then flushes the stream.
flush flushes the output stream without necessarily inserting a newline.
For example:
cout << "Hello" << flush;
forces the output to be sent from the buffer to the associated output device.