简体   繁体   中英

Cross-platform GUI application console for debug messages C++

I am programming a game in C++. I want to print debugging messages from within my code using std::cout, but as this is a GUI application there is no console to print to by default. I have tried simply running it from CMD like this:

start Debug/hydro.exe

But to no avail.

On Windows 8 x86_64 using Visual Studio 2012 with a Win32 project, the following code achieves what I am looking for:

#include <Windows.h>
...
AllocConsole();
freopen("CONIN$", "r",stdin);
freopen("CONOUT$", "w",stdout);
freopen("CONOUT$", "w",stderr);

However, I believe that this not cross-platform (do correct me if I am wrong!) and would like my application to work on Linux and Mac OS X.

Is there a cross-platform solution to this? Of course, the simpler the better!

I'm not aware of any product that does this in a Linux world - you are expected to start the code from a shell, and the output appears in the shell window.

Wrapping like this should help:

#ifdef _WIN32
// Windows-only code here
#endif

When outside of Windows, the code will not be compiled, when inside of the Windows the code will be compiled!

If your code depends on <Windows.h> it is DEFINITELY NOT cross-platform.

Take a look at log4cxx for cross-platform logging. It's a pretty stable, mature platform.

PS: Good luck with cross-platform GUI programming. GUI programming is typically very platform-specific. A framework like Qt will probably help a lot, and if you are doing 3D graphics, be sure to use OpenGL rather than DirectX.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM