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.
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';
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With