Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I find out the date of when my source code was compiled?

Is it possible to store and display the date of when my project was compiled?

I'd like to print this date when the program starts in order to know which version is used. Currently, I am doing this by hand, which is rather cumbersome.

I am using Visual Studio 2010.

like image 454
Fabian Avatar asked Dec 02 '22 17:12

Fabian


1 Answers

C++ specifies that there's a special preprocessor macro called __DATE__ that is a string literal of when the compilation happened. There's also a corresponding __TIME__ macro.

You can use at such:

const std::string compilation_date = __DATE__;
const std::string compilation_time = __TIME__;

...

std::cout << "This source file was compiled on date " << compilation_date
          << " and at the time " << compilation_time << '\n';
like image 174
Some programmer dude Avatar answered Dec 11 '22 09:12

Some programmer dude