如何在Windows中编写C++调试函数

how to write a C++ debug function in Windows?

本文关键字:C++ 调试 函数 Windows      更新时间:2024-05-10

我想写一个像linux一样的windows调试函数:

#define debug(fmt, ...)  printf("[%s:%d]"fmt"n", __FUNCTION__, __LINE__, ##__VA_ARGS__)

为了使类似的字符串串联工作,字符串之间需要空格。所以这部分:

"[%s:%d]"fmt"n"

的更改

"[%s:%d]" fmt "n"

否则,fmt被假定为字符串文字运算符(operator""fmt(,这在这里是不需要的。

不要忘记将<cstdio>包含在printf中,这样它就可以按预期工作了。