1 #include2 #include 3 #include 4 5 using namespace std; 6 7 int main( int argc, char *argv[]); 8 void timestamp( void); 9 10 int main( int argc, char *argv[])11 // argv : a pointer ( point to an array ( array stores pointers))12 {13 int i;14 bool VERBOSE = true;15 16 if( VERBOSE)17 {18 timestamp();19 20 cout << "\n";21 cout << "ARGS\n";22 cout << " C++ version\n";23 cout <<"\n";24 cout << " Compiled on " << __DATE__ << "at" << __TIME__ << ".\n"; //显示编译时的时间25 cout << __FILE__ <
学习到的东西:编译器预定义到的宏。
再次理解main函数的参数“ char *argv[]",argv[]是个数组,数组里面存储的是char* 指针,即数组里面的内容是指针。
// wchar.h 中struct tm { int tm_sec; /* seconds after the minute - [0,59] */ int tm_min; /* minutes after the hour - [0,59] */ int tm_hour; /* hours since midnight - [0,23] */ int tm_mday; /* day of the month - [1,31] */ int tm_mon; /* months since January - [0,11] */ int tm_year; /* years since 1900 */ int tm_wday; /* days since Sunday - [0,6] */ int tm_yday; /* days since January 1 - [0,365] */ int tm_isdst; /* daylight savings time flag */ };
time()获得时间信息;localtime()转换信息为时间表示的形式;strftime()将时间转换为字符串的形式,便于输出。
原型:time_t time( time_t* timer) The value returned generally represents the number of seconds since 00:00 hours, Jan 1, 1970 UTC. 将返回的值返回到timer里面。如果timer是NULL 则返回就完了。
源代码来源:
ctime: