Print Date and Time In Visual Studio C++ build?

后端 未结 5 1128
故里飘歌
故里飘歌 2020-12-17 23:49

How would I print the date and time for the purposes of the build. Ie: When the console for my application starts up I want to do this:

Binary B         


        
5条回答
  •  谎友^
    谎友^ (楼主)
    2020-12-17 23:58

    Similar to Virne's answer I created a simple header file called "BuildDate.h" with the following contents:

    #define BUILD_DATE __DATE__ " " __TIME__
    

    I touch the file using GnuWin32 touch command in my pre-build event:

    touch.exe BuildDate.h
    

    Then I include the header file in any code where I want access to the BUILD_DATE string. E.g.:

    #include "BuildDate.h"
    ...
    logger->Log("Build Date: " BUILD_DATE);
    

提交回复
热议问题