现在的位置: 首页 > 综合 > 正文

C/C++的一些预定义宏

2013年08月14日 ⁄ 综合 ⁄ 共 500字 ⁄ 字号 评论关闭

 收集自网络:

__FILE__:当前源代码文件名的字符串文字

__LINE__:当前源代码中的行号的整数常量

__DATE__:进行预处理的日期(“Mmm dd yyyy”形式的字符串文字)

__TIME__:源文件编译时间,格式微“hh:mm:ss”

__func__:当前所在函数名,在C++中为__FUNCTION__

C++的测试代码如下(g++),其中VC中不支持__func__ :

#include
using namespace std; 

#ifndef __func__ 
#define __func__  (__FUNCTION__) 
#endif 
 
void func() 
{
    cout<<"func name is:"<<__func__<<endl;    
    cout<<"func name is:"<<__FUNCTION__<<endl;    
}
 
int main()
{
    cout<<"date is :"<<__DATE__<<endl;
    cout<<"time is :"<<__TIME__<<endl;
    cout<<"file is :"<<__FILE__<<endl;
    cout<<"line is :"<<__LINE__<<endl;
    func();
}

 

抱歉!评论已关闭.