Solved

How can I log the date when a program was compiled in visual studio?

Posted on 2007-11-27
6
581 Views
Last Modified: 2013-12-14
Hi,

I am writing a VS 2005 native c++ console application. Each time I run it, I would like it to log to file the date on which it was compiled.  How can I do this?  

I know how to log stuff to files... the thing I can't figure out is how to obtain a date once at compile time such that it remains a runtime constant.

thanks
0
Comment
Question by:highqllc
6 Comments
 
LVL 53

Accepted Solution

by:
Infinity08 earned 250 total points
ID: 20359102
You could use the __DATE__ and __TIME__ macro's. As example :

        printf("%s %s\n", __DATE__, __TIME__);
0
 
LVL 53

Expert Comment

by:Infinity08
ID: 20359115
or more C++-y :

        std::cout << __DATE__ << " " << __TIME__ << std::endl;
0
 
LVL 86

Assisted Solution

by:jkr
jkr earned 150 total points
ID: 20359118
The predefined macro __DATE__ allowes to do that, e.g.

printf("Module compiled on %s", __DATE__);
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 14

Assisted Solution

by:wayside
wayside earned 100 total points
ID: 20359122
Use the __DATE__ macro. Add something like

char *compileDate = __DATE__;

in your code.
0
 
LVL 86

Assisted Solution

by:jkr
jkr earned 150 total points
ID: 20359124
0
 

Author Comment

by:highqllc
ID: 20359137
Awesome. Perfect.

How on earth do I divy out points here? :)
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

When writing generic code, using template meta-programming techniques, it is sometimes useful to know if a type is convertible to another type. A good example of when this might be is if you are writing diagnostic instrumentation for code to generat…
This article shows you how to optimize memory allocations in C++ using placement new. Applicable especially to usecases dealing with creation of large number of objects. A brief on problem: Lets take example problem for simplicity: - I have a G…
THe viewer will learn how to use NetBeans IDE 8.0 for Windows to perform CRUD operations on a MySql database.
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.

911 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now