views:

277

answers:

3

I created an Empty Project in Visual C++, but now I need the Console to display debug output.

How can I enable the Console without recreating the project or show the output in the VS output window?

Thanks in advance Attic

A: 

AllocConsole

R Samuel Klatchko
+1  A: 

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, detaching the process from it, as well.

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

Reed Copsey
When I've done this in the past, there were hoops I had to jump through for stdout to actually make it to the console window. By default it doesn't.
dash-tom-bang
@dash-tom-bang: Very true. The console, by default, won't redirect all standard output. I added a link to a page showing working code that demonstrates everything required.
Reed Copsey
A console shows up, but the data I put into std::cout does not show up there.
Attic
Wow, thats a lot of code for a task I thought would be easy.Thank you for the link, I will mark this answer as solution.
Attic
Yeah - it's kind of annoying - but it's a useful set of code to bookmark. I find that I've done this multiple times...
Reed Copsey