Predefined Macros

Macro Description
__DATE__ The current date as a character literal in "MMM DD YYYY" format
__TIME__ The current time as a character literal in "HH:MM:SS" format
__FILE__ This contains the current filename as a string literal.
__LINE__ This contains the current line number as a decimal constant.
__STDC__ Defined as 1 when the compiler complies with the ANSI standard.
#include <iostream>
using namespace std;

int main () {

	cout << "File " << __FILE__ << endl ;
	cout << "Date " << __DATE__ << endl ;
	cout << "Time " << __TIME__ << endl ;
	cout << "Line " << __LINE__ << endl ;
	cout << "ANSI " << __STDC__ << endl ;

	return 0;
}

Compile & run:

File ..\working.cpp
Date Apr 5 2013
Time 10:32:46
Line 9
ANSI 1

Leave a Reply