您的位置:首页 > 其它

如何获取当前编译的文件标题和行数

2012-09-16 10:55 274 查看
如何获取当前编译的文件标题和行数

今天突然看到一个面试题,觉得挺有意思的就你把MSDN的查到的几个宏贴出来分享。

MacroDescription
__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;

}

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: