C標(biāo)準(zhǔn)中指定了一些預(yù)定義的宏
__DATE__
進行預(yù)處理的日期(“Mmm dd yyyy”形式的字符串文字)
__FILE__
代表當(dāng)前源代碼文件名的字符串文字
__LINE__
代表當(dāng)前源代碼中的行號的整數(shù)常量
__TIME__
源文件編譯時間,格式微“hh:mm:ss”
__func__
當(dāng)前所在函數(shù)名
上述宏的使用:
//cpp.cpp
#include <iostream>
#include <cstdlib>
void why_me();
using namespace std;
int main(int argc, char* argv[])
{
cout<<"The file is "<<__FILE__<<"."<<endl;
cout<<"The date is "<<__DATE__<<"."<<endl;
cout<<"The time is "<<__TIME__<<"."<<endl;
cout<<"This is line "<<__LINE__<<"."<<endl;
cout<<"This function is "<<__func__<<"."<<endl;
why_me();
system("PAUSE");
return 0;
}
void why_me(void)
{
cout<<"This function is "<<__func__<<"."<<endl;
cout<<"The file is "<<__FILE__<<"."<<endl;
cout<<"This is line "<<__LINE__<<"."<<endl;
}
輸出結(jié)果如下:

Trackback: http://www.blogcn.com/user65/yk103/index.html