TanZek's 技术空间

勇往直前,专注于技术...

首页 新随笔 联系 聚合 管理
  7 Posts :: 19 Stories :: 13 Comments :: 0 Trackbacks

C标准中指定了一些预定义的宏
                  __DATE__
                  进行预处理的日期(“Mmm dd yyyy”形式的字符串文字)

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

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

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

                  __func__
                  当前所在函数名 


上述宏的使用:
//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;
}


输出结果如下:
output.bmp


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

posted on 2005-12-09 18:43 TanZek 阅读(364) 评论(0)  编辑 收藏 引用 所属分类: C++

只有注册用户登录后才能发表评论。
网站导航: 博客园   IT新闻   BlogJava   知识库   博问   管理