1. 程式人生 > >C++下用巨集定義除錯列印小技巧

C++下用巨集定義除錯列印小技巧

#define DEBUG
#define LOG_FILE __FILE__".log"

#ifdef DEBUG
#define dbgprint(format,args...) fprintf(stderr, format, ##args)
#define logprint(format,args...) {FILE* fp=fopen(LOG_FILE,"a+");fprintf(fp,"line %d: "format,__LINE__,##args);fclose(fp);}
#else
#define dbgprint(format,args...)
#define logprint(format,args...)
#endif