c++程序中写测试log到文件的简单实现

1、int WriteToLog(char* str)
{
FILE* log;
log = fopen("D:\\testlog.txt", "a+");
if (log == NULL){
//OutputDebugString("Log file open failed.");
return -1;
}
fprintf(log, "%s\n", str);
fclose(log);
return 0;
}

 

 

 2、带时间的实现

  1. void WriteLog(char * szLog)  
  2. {  
  3.                  SYSTEMTIME st;  
  4.                  GetLocalTime(&st);  
  5.                  FILE *fp;  
  6.                  fp=fopen("D:\\log.txt","at");  
  7.                  fprintf(fp,"MyLogInfo: %d:%d:%d:%d ",st.wHour,st.wMinute,st.wSecond,st.wMilliseconds);  
  8.                  fprintf(fp,szLog);  
  9.                  fclose(fp);  
  10.                  OutputDebugStringA(szLog);  

 

 

上一篇:Higher Math


下一篇:赣州网站建设一定要重视代码编写和后期优化