如何获取当前编译的文件标题和行数
2012-09-16 10:55
274 查看
如何获取当前编译的文件标题和行数
今天突然看到一个面试题,觉得挺有意思的就你把MSDN的查到的几个宏贴出来分享。
实例:
#include <iostream>
using namespace std;
int main()
{
int len = __LINE__;
char *file = __FILE__;
char *date = __DATE__;
char *time = __TIME__;
char *dataAndTime = __TIMESTAMP__;
cout<<"Length:"<<len<<endl<<"File:"<<file<<endl;
cout<<"data:"<<data<<endl;
cout<<"Time:"<<time<<endl;
cout<<"DataAndTime:"<<dataAndTime<<endl;
return 0;
}
今天突然看到一个面试题,觉得挺有意思的就你把MSDN的查到的几个宏贴出来分享。
Macro | Description |
__DATE__ | The compilation date of the current source file. The date is a string literal of the formMmm dd yyyy. The month nameMmm is the same as for dates generated by the library functionasctime declared in TIME.H. |
__FILE__ | The name of the current source file. __FILE__ expands to a string surrounded by double quotation marks. |
__LINE__ | The line number in the current source file. The line number is a decimal integer constant. It can be altered with a#line directive. |
__STDC__ | Indicates full conformance with the ANSI C standard. Defined as the integer constant 1 only if the /Za compiler option is given and you are not compiling C++ code; otherwise is undefined. |
__TIME__ | The most recent compilation time of the current source file. The time is a string literal of the formhh:mm:ss. |
__TIMESTAMP__ | The date and time of the last modification of the current source file, expressed as a string literal in the formDdd Mmm Date hh:mm:ss yyyy, whereDdd is the abbreviated day of the week andDate is an integer from 1 to 31. |
#include <iostream>
using namespace std;
int main()
{
int len = __LINE__;
char *file = __FILE__;
char *date = __DATE__;
char *time = __TIME__;
char *dataAndTime = __TIMESTAMP__;
cout<<"Length:"<<len<<endl<<"File:"<<file<<endl;
cout<<"data:"<<data<<endl;
cout<<"Time:"<<time<<endl;
cout<<"DataAndTime:"<<dataAndTime<<endl;
return 0;
}
相关文章推荐
- php如何获取文件行数
- 如何获取当前程序文件的路径 Current Path
- 原生js如何获取当前所加载网页的文件路径和名称
- 如何获取当前程序文件的路径【转载】
- WPF Browser 中如何获取当前路径(临时文件中)?
- C# 获取当前文件名、执行函数、执行代码行数和列数
- 如何获取当前程序文件的路径
- Tomcat初始化方法中如何注入配置文件内容以及获取当前服务器端口号
- PHP如何获取文件行数
- 如何在浏览器中获取当前执行的脚本文件名
- 如何获取当前程序文件的路径
- 如何在mapreduce方法中获取当前使用文件(get file name)
- C# 获取当前文件名、执行函数、执行代码行数和列数
- 如何获取当前程序文件的路径CurrentPath
- linux 如何获取当前文件路径(source如何获取当前文件路径 bash如何获取当前文件路径)
- C# 获取当前文件名、执行函数、执行代码行数和列数
- 如何获取当前程序文件的路径 Current Path
- 如何获取当前程序文件的路径 Current Path
- Silverlight中如何获取当前xap文件的地址以及部署了当前xap的页面地址
- Treeview的click事件中,如何知道当前点击的是子结点,并且如何获取子结点的标题?