1、ANSI C标准中常用的预定义宏:
- DATE: 在源文件中插入当前的编译日期
- TIME:在源文件中插入当前编译时间;
- FILE:在源文件中插入当前源文件名;
- LINE:在源代码中插入当前源代码行号;
- FUNCTION:在源代码中插入当前所在函数名称;
- STDC:当要求程序严格遵循ANSI C标准时该标识被赋值为1;
- __cplusplus :当编写C++程序时该标识符被定义。
2、使用展示:
// test.cpp
int main()
{
cout << "file name: " << __FILE__ << " func name: " << __FUNCTION__<< " line num: " << __LINE__ <<endl;
return 0;
}
输出:file name: ../src/test.cpp func name: main line num: 17