摘要:1、 intWriteToLog(char*str){FILE*log;log=fopen(“D:\\testlog.txt”,“a+”);if(log==NULL){//OutputDebugString(“Logfileopenfailed.”);return-1;}fprintf(日志,“%s\n”,str);fclose(日志);return0;}2.VoidWriteLog随时间的实现
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、带时间的实现
- voidWriteLog(char*szLog)
- {
- SYSTEMTIMEst;
- GetLocalTime(&st);
- FILE*fp;
- fp=fopen("D:\\log.txt","at");
- fprintf(fp,"MyLogInfo:%d:%d:%d:%d",st.wHour,st.wMinute,st.wSecond,st.wMilliseconds);
- fprintf(fp,szLog);
- fclose(fp);
- OutputDebugStringA(szLog);
- }