简体   繁体   English

C++ 17 | 调试输出

[英]C++ 17 | Debugging Output

What I want to do, is when I run a program in debug mode, I want it to cout to the console or even possibly the game window what it's doing, like for an example, GameWindow::Initialized(args...) , and I want that to run throughout the program until it ends.我想要做的是,当我在调试模式下运行程序时,我希望它向控制台甚至可能是游戏窗口输出它正在做什么,例如GameWindow::Initialized(args...) ,我希望它在整个程序中运行,直到它结束。 Also, if I get the functions for that (I believe there is some on google), instead of checking if it's in debug mode: 'if (_Debug) {}', for each time I want to call the function that cout's to the screen, is there a way I can just do the debug checking once and have it done?另外,如果我获得了相应的函数(我相信 google 上有一些),而不是检查它是否处于调试模式:'if (_Debug) {}',因为每次我想调用 cout 的函数到屏幕,有没有办法我可以只进行一次调试检查并完成它?

My guess is that I could create a thread and have it check if it's in debug mode, I could use a function that checks live what the game is doing and have that run continuously.我的猜测是我可以创建一个线程并让它检查它是否处于调试模式,我可以使用一个函数来实时检查游戏正在做什么并让它连续运行。 I need to do more on threading because I've not done it in a while.我需要在线程上做更多的工作,因为我已经有一段时间没有这样做了。

Thanks for reading, if you could help me or even agree that my method would work, I'd highly appreciate that :)感谢阅读,如果您能帮助我,甚至同意我的方法可行,我将不胜感激:)

Normally you #define NDEBUG if you are not in debug mode.通常,如果您未处于调试模式,则#define NDEBUG So you can这样你就可以

#ifndef NDEBUG
    cout << "test\n";
#endif

Alright, so I've just decided to do something really simple, so all I done is define a log function which takes in a parameter and then output that to the console, if debug mode is on, otherwise, all I done is do an #else and then do the same thing, but I didn't output it.好的,所以我决定做一些非常简单的事情,所以我所做的就是定义一个日志函数,它接受一个参数,然后将其输出到控制台,如果调试模式打开,否则,我所做的就是做一个#else 然后做同样的事情,但是我没有输出它。 So just #define LOG(x) /* Nothing Else */ ->This is for release所以只是 #define LOG(x) /* 没有别的 */ ->这是为了发布

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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