Where does fprintf(stdout/stderr) print to in Visual Studio when compiling Win32 app? I keep hearing it goes to the output but I can't see it!.
Whats the standard way of printing to the output log without having a console window in c++?
Where does fprintf(stdout/stderr) print to in Visual Studio when compiling Win32 app? I keep hearing it goes to the output but I can't see it!.
Whats the standard way of printing to the output log without having a console window in c++?
If your program is linked with /SUBSYSTEM:WINDOWS you will not see the console output unless you allocate a console.
Here is code for the allocate console option.With this method you should not need to mess with linker settings or create a WinMain.
If you do not want to allocate a console directly you can also change the subsystem from /SUBSYSTEM:windows to /SUBSYSTEM:CONSOLE via changing the Subsystem of the linker settings. Remember when /SUBSYSTEM:CONSOLE is enabled the gui will still work the same as before but windows will create a console window for you along with your application.
In my Qt code that is all that is needed. However when I tried MFC in VisualStudio and set the subsystem to console via the linker setting. I got the following error:
This is caused by the entry point defaulting to main() in console applications and WinMain in windows applications. To fix this I had to add the following to the Entry Point setting of the Advanced Linker settings: "wWinMainCRTStartup"
In the comments Ben Voigt suggested an alternate method. Using editbin to change the subsystem does not require a change in the entry point. This is indeed the case. I put removed the entry point and put windows back as the subsystem built the test application then used editbin to change the subsystem using the following command:
And I got the output I expected in the console:
Note: With the editbin method you need to renable this every time you update the executable.
And finally on either method once you have the console printf or std::cout will work. For example in my test MFC application I added the following line to the constructor of the CMFCApplication1App class: