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

时间:2012-12-20 15:49:51

标签: c++ c

  

可能重复:
  C/C++ line number

我想显示触发printf的行号?

看起来像这样:

printf("the line number is: %d",SOME_LIBC_MACRO);

怎么做?

1 个答案:

答案 0 :(得分:12)

使用__LINE__

printf("the line number is: %d", __LINE__);

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