如何获取当前编译的文件标题和行数
今天突然看到一个面试题,觉得挺有意思的就你把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;
}