Use project debugging
If it is a linux environment , note that there must be a space in front of fmt here
, otherwise an error will be reported
error: unable to find string literal operator ‘operator""fmt’ with ‘const char [4]’, ‘long unsigned int’ arguments
the code
#include <stdio.h>
#include <stdlib.h>
#define DEBUG_ON
#ifdef DEBUG_ON
#define DEBUG(fmt, args...) printf("[FILE = %s][FUNCTION = %s][LINE = %d] ["fmt"]\n",__FILE__,__FUNCTION__,__LINE__,##args)
#else
#define DEBUG(fmt, args...) do{
}while(0)
#endif
int main()
{
int a = 0;
DEBUG("a = %d",a);
DEBUG("test");
return 0;
}
result:
[FILE = debug.c][FUNCTION = main][LINE = 15] [a = 0]
[FILE = debug.c][FUNCTION = main][LINE = 16] [test]
Algorithm topic debugging
Note that there must be a space in front of fmt here
, because most of the operating environment of oj is linux, there needs to be a space in front of linux.
#define DEBUG_ON
#ifdef DEBUG_ON
#define DEBUG(fmt, args...) printf("" fmt"",##args)
#else
#define DEBUG(fmt, args...) do{
}while(0)
#endif
int main() {
int n = 5;
int b[] = {
1, 2, 2, 2, 2};
DEBUG("b[] = ");
for (int i = 0; i < n; i++) {
DEBUG("%lld ", b[i]);
}
DEBUG("\n");
return 0;
}
result
b[] = 1 2 2 2 2