C/C++ 除錯(DEBUG)專用LOG函數 [顯示檔案/行數/函數 等相關位置]
C/C++ 除錯(DEBUG)專用LOG函數 [顯示檔案/行數/函數 等相關位置]
資料來源: https://mp.weixin.qq.com/s/svsBnT_kDtNCAXgUALI__g
完整可執行程式碼:
#include <iostream>
#include <cstdio>
using namespace std;
#define DBG_PRINTF(fmt, args...) \
do\
{\
printf("<<File:%s Line:%d Function:%s>> ", __FILE__, __LINE__, __FUNCTION__);\
printf(fmt, ##args);\
}while(0)
void Pause()
{
printf("Press Enter key to continue...");
fgetc(stdin);
}
int main()
{
cout << "Hello world!" << endl<< endl;
int a=1,b=2,c=a+b;
printf("a=%d,b=%d,c=a+b\n\n",a,b);
if(c)
{
DBG_PRINTF("C>%d\n\n",0);
}
else
{
DBG_PRINTF("C<%d\n\n",0);
}
Pause();
return 0;
}
%E5%B0%88%E7%94%A8LOG%E5%87%BD%E6%95%B8/%E7%B5%90%E6%9E%9C%E5%9C%96.png?raw=true)
完整圖文介紹: