如何在printf中显示源代码的行号

dev*_*per 2 c c++

可能重复:
C/C++行号

我想显示触发printf的行号?

它可能看起来像这样:

printf("the line number is: %d",SOME_LIBC_MACRO);
Run Code Online (Sandbox Code Playgroud)

怎么做?

sim*_*onc 12

使用__LINE__

printf("the line number is: %d", __LINE__);
Run Code Online (Sandbox Code Playgroud)

GCCVisual Studio可以使用其他预定义宏列表