[英]Cross-platform GUI application console for debug messages C++
I am programming a game in C++. 我正在用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.
我想使用std :: cout从代码中打印调试消息,但是由于这是一个GUI应用程序,因此默认情况下没有控制台可以打印到该消息。 I have tried simply running it from CMD like this:
我试图从CMD像这样简单地运行它:
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: 在使用带有Win32项目的Visual Studio 2012的Windows 8 x86_64上,以下代码实现了我想要的功能:
#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. 但是,我相信这不是跨平台的(如果我错了,请纠正我!),希望我的应用程序可以在Linux和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. 我不知道在Linux世界中能做到这一点的任何产品-您应该从shell启动代码,并且输出出现在shell窗口中。
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! 在Windows外部时,将不编译代码,在Windows内部时,将不编译代码!
If your code depends on <Windows.h>
it is DEFINITELY NOT cross-platform. 如果您的代码依赖于
<Windows.h>
则绝对不是跨平台的。
Take a look at log4cxx for cross-platform logging. 查看用于跨平台日志记录的log4cxx 。 It's a pretty stable, mature platform.
这是一个非常稳定,成熟的平台。
PS: Good luck with cross-platform GUI programming. PS:跨平台GUI编程祝您好运。 GUI programming is typically very platform-specific.
GUI编程通常是非常特定于平台的。 A framework like Qt will probably help a lot, and if you are doing 3D graphics, be sure to use OpenGL rather than DirectX.
像Qt这样的框架可能会很有帮助,如果您要进行3D图形处理,请确保使用OpenGL而不是DirectX。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.