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、带时间的实现
- void WriteLog(char * szLog)
- {
- SYSTEMTIME st;
- 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);
- }