本文介绍了录音的时候,你编译源的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个源文件。当我编译code,我想的可执行文件记住当它被建立。我想知道,如果它是可能的。例如:
INT的main(){
time_t的T =? //时值这一行编译
//打印出的t值一定的格式。
返回ŧ
}
解决方案
您可以使用 __ TIME __
和 __ DATE __
宏以获得。这是一个字符串,所以哟需要<一个href=\"http://stackoverflow.com/questions/321793/date-time-conversion-string-re$p$psentation-to-time-t\">convert到一个 time_t的
从那里。
一个简单的例子我放在一起:
的#include&LT;&time.h中GT;
#包括LT&;&iostream的GT;
#包括LT&;&了cassert GT;time_t的build_time(){
静态为const char *内置= __DATE____TIME__;
结构TM吨;
为const char * RET = strptime(建%B%D%Y%H:%M:%S,&amp; T公司);
断言(RET);
返回mktime(&amp; T公司);
}诠释主(){
性病::法院LT&;&LT; build_time()&所述;&下;的std :: ENDL;
}
我是有点担心如何互动与不同的语言环境,所以我不得不在最近的C标准咋一看,发现下面这段文字:
asctime
is quite clear that:
But %b
of strptime()
says:
So you need to be aware that this is making an assumption about what the locale will be set to at run time.
(You could in theory write a constexpr
function or two to do that at compile time in C++11, but that's non-trivial to say the least!)
这篇关于录音的时候,你编译源的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!