您的位置:首页 > 编程语言 > C语言/C++

预定义宏 ANSI C

2016-05-17 03:09 381 查看
   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

除此之外,还有微软编译器专用的预定义宏
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  C++ 编译器 c语言