INFO: Endl Flushes the cout Buffer Immediately Upon Execution (83081)



The information in this article applies to:

  • Microsoft Visual C++ 1.0
  • Microsoft Visual C++ 1.5
  • Microsoft Visual C++ 1.51
  • Microsoft Visual C++ 1.52
  • Microsoft Visual C++ 2.0
  • Microsoft Visual C++ 2.1
  • Microsoft Visual C++ 4.0
  • Microsoft Visual C++, 32-bit Enterprise Edition 5.0
  • Microsoft Visual C++, 32-bit Enterprise Edition 6.0
  • Microsoft Visual C++, 32-bit Professional Edition 5.0
  • Microsoft Visual C++, 32-bit Professional Edition 6.0
  • Microsoft Visual C++, 32-bit Learning Edition 6.0

This article was previously published under Q83081

SUMMARY

In these products, the cout class uses a buffering system for data that may not be flushed immediately. Because cout usually handles small messages, several messages are usually needed to fill the buffer, which will cause the data to be written to the standard output handle. In some cases, this can cause considerable delay when writing output to the screen during a debugging session. This problem can be avoided, however, by using the endl manipulator. When appended to the end of a cout call, the endl manipulator inserts a newline character and then flushes the buffer.

MORE INFORMATION

Sample Code

/* Compile options needed: none
*/ 

#include <iostream.h>

void main(void)
{
  cout << "This string will be buffered";
  cout << "This string will be flushed immediately" <<endl;
}
				
For more information on the other methods to flush the cout buffer, please see the following article in the Microsoft Knowledge Base:

94227 INFO: Output Stream cout Is Buffered


Modification Type:MinorLast Reviewed:7/5/2005
Keywords:kbinfo kbLangCPP KB83081