1 int WriteLog(const char *format, ...) 2 { 3 //判断是否为第一次创建该文件 4 if(!m_hFirstOpen) 5 { 6 m_hFirstOpen = TRUE; 7 DeleteFile(L".\\1.LOG"); 8 } 9 FILE* pFile = fopen(".\\1.LOG","a+"); 10 if(!pFile) 11 { 12 return -1; 13 } 14 va_list arg; 15 int done; 16 17 va_start (arg, format); 18 //done = vfprintf (stdout, format, arg); 19 20 time_t time_log = time(NULL); 21 struct tm* tm_log = localtime(&time_log); 22 //打印时间 23 fprintf(pFile, "%04d-%02d-%02d %02d:%02d:%02d ", tm_log->tm_year + 1900, tm_log->tm_mon + 1, tm_log->tm_mday, tm_log->tm_hour, tm_log->tm_min, tm_log->tm_sec); 24 25 done = vfprintf (pFile, format, arg); 26 va_end (arg); 27 28 fflush(pFile); 29 fclose(pFile); 30 return done; 31 } 32
原文:https://www.cnblogs.com/cyymfm1314/p/9116206.html