Visual C ++ Console Enable

I created an empty project in Visual C ++, but now I need a console to display the debug output.

How to turn on the console without recreating the project or show the output in the VS output window?

+5
source share
3 answers

You can always call AllocConsole in code to create a console for your application and attach it to the process. FreeConsole will remove the console by disconnecting the process from it.

If you want all standard output stream data to go to the console, you also need to use SetStdHandle to redirect the output accordingly. Here is a page showing the working code to complete this complete process , including highlighting the console and redirecting the output.

+10
source

Here is the code you can paste to get a console window in a Windows GUI'd application that starts in WinMain. There are other ways to do this, but this is the most compact snippet I have found.

//Alloc Console
//print some stuff to the console
//make sure to include #include "stdio.h"
//note, you must use the #include <iostream>/ using namespace std
//to use the iostream... #incldue "iostream.h" didn't seem to work
//in my VC 6
AllocConsole();
freopen("conin$","r",stdin);
freopen("conout$","w",stdout);
freopen("conout$","w",stderr);
printf("Debugging Window:\n");
+15
source

All Articles