C编译器的7个预定义宏(Pre-defined Macros),可以方便的打印程序信息,方便调试。
#include <iostream>
using namespace std;
void printMacros(){
cout<<"date "<<__DATE__<<endl;
cout<<"file "<<__FILE__<<endl;
cout<<"func "<<__func__<<endl;
cout<<"line "<<__LINE__<<endl;
cout<<"stdc "<<__STDC__<<endl;
cout<<"time "<<__TIME__<<endl;
cout<<"timestamp "<<__TIMESTAMP__<<endl;
}
int main() {
printMacros();
return 0;
}
输出:
date May 16 2016
file prog.cpp
func printMacros
line 8
stdc 1
time 22:14:41
timestamp Mon May 16 22:14:41 2016
除此之外,还有微软编译器专用的预定义宏。