Is it possible to have an embedded output console as part of the VS2012 window instead of opening cmd upon running?
For example, in Eclipse output is directed to the "Console" pane by default, and I would like to achieve something similar in VS2012, if it is available.
Here is a complete example of the code involved to do this:
http://blog.tomaka17.com/2011/07/redirecting-cerr-and-clog-to-outputdebugstring/
Basically the author creates a new
std::basic_stringbuf
that uses the MSVC functionOutputDebugString()
and binds it toclog
andcerr
viastd::cerr.rdbuf(&newStreamBuf)
. This should also work forcout
.I actually compiled his code and had some issues with it, here is the corrected version:
cpp file:
Header file:
And here is the usage along with some test cases:
I tested all this with Visual Studio 2012 and it works fine. C-Style functions like
printf
do not work though...It's a good idea to create debug output functions that you can then modify as required to redirect output where it needs to go. Keep in mind though that text boxes in Windows are very, very slow compared to the console, and even the console isn't that fast.
If you have a lot of debug output it will have a noticeable effect on your application. For example I was doing some comms with an embedded device and spitting out the raw data to the debug window. It took about 4 minutes to extract the data I needed. I switched the debug output to a real console window and it took about 20 seconds.
These days I just open a real console window using AllocConsole().