I've got a win32 project that I've loaded into Visual Studio 2005. I'd like to be able to print things to the Visual Studio output window, but I can't for the life of me work out how. I've tried 'printf' and 'cout <<' but my messages stay stubbornly unprinted.
Is there some sort of special way to print to the Visual Studio output window?
You can use
OutputDebugString
.OutputDebugString
is a macro that depending on your build options either maps toOutputDebugStringA(char const*)
orOutputDebugStringW(wchar_t const*)
. In the later case you will have to supply a wide character string to the function. To create a wide character literal you can use theL
prefix:Normally you will use the macro version together with the
_T
macro like this:If you project is configured to build for UNICODE it will expand into:
If you are not building for UNICODE it will expand into:
If the project is a GUI project, no console will appear. In order to change the project into a console one you need to go to the project properties panel and set:
This solution works only if you had the classic "int main()" entry point.
But if you are like in my case (an openGL project), you don't need to edit the properties, as this works better:
printf and cout will work as usual.
If you call AllocConsole before the creation of a window, the console will appear behind the window, if you call it after, it will appear ahead.
Consider using the VC++ runtime Macros for Reporting _RPTN() and _RPTFN()
Example...
Or you can use the VC++ runtime functions _CrtDbgReport, _CrtDbgReportW directly.