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

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

 

今天突然看到一个面试题,觉得挺有意思的就你把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;
}

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值