INFO: Using cout in an Application and DLL

Last reviewed: September 30, 1997
Article ID: Q101185

The information in this article applies to:
  • Microsoft Visual C++ for Windows, versions 1.0, 1.5
  • Microsoft Visual C++ 32-bit Edition, versions 1.0, 2.0, 4.0, 5.0

The standard output stream (cout) can be used in an application or dynamic- link library (DLL) to display information. When using cout in an application and a DLL simultaneously, special care is needed to ensure that the text display is synchronized.

Because the cout text stream is buffered, text from a DLL may not appear correct relative to text from the application. To correct this problem, always use the endl manipulator when outputting text with cout. Below is an example:

   cout << "Hello World" << endl;

The endl manipulator inserts a newline character and then flushes the stream buffer. This ensures that text displayed from the application and DLL is synchronized.
Keywords          : CPPLngIss
Version           : WINDOWS:1.0,1.5;WINDOWS NT:1.0,2.0,4.0,5.0;
Platform          : NT WINDOWS
Issue type        : kbinfo


================================================================================


THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY.

Last reviewed: September 30, 1997
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.