C++ and STL
  Common Issues
  Destructor
  regex
  string
 MFC
  CButton
  CDialog
  CEdit
  CInternetSession
  CWinThread
  CWnd
 MS VS FAQ
  Compiling, building
  Debugging
  Editor
  Settings
 Win32, API
  Console
  File System
  Graphics
  Internet functions
  Kernel objects
  Security
  Sound
  Thread, process
  Window
 Windows NT/2K*
  Logon, logoff...
  Networking
  Service Packs
 | About
  About
  Links & Freeware

Powered by
CoderTown



How to add console window to dialog based / SDI / MDI application

While debugging an application it's often useful to have trace output window for momentary data logging rather then using MessageBox() for this purpose. The simplest method is to create a console window and to redirect standard I/O to it like this:

   AllocConsole();
   freopen("conin$", "r", stdin); 
   freopen("conout$", "w", stdout); 
   freopen("conout$", "w", stderr); 

After that, all printf and cout calls will output to this window. Even input will work for it: you can use getch() from conio.h to pause a thread. Be aware - one process may have only one console window created/attached. See a link below for alternative solution.

Useful links: Codeguru - Write debug output to console window

Created: 2004-02-11
Updated: 2004-02-11

Google
 
Web visualcpp.net
msdn.microsoft.com codeguru.com