一行一行写数据到文件中

     FILE* fpLog = fopen("log.txt", "a+");
if (fpLog != NULL)
{
int nStatus = 12;
CString str;
str.Format(_T("%d"),nStatus);
CTime curTime = CTime::GetCurrentTime();
CString strCurTime = "";
strCurTime.Format("%04d-%02d-%02d %02d:%02d:%02d", curTime.GetYear(), curTime.GetMonth(), curTime.GetDay(),
curTime.GetHour(), curTime.GetMinute(), curTime.GetSecond());


CString strLogMsg = "";
strLogMsg.Format("[%s] :[%s]\r\n", strCurTime,str);
   fwrite(strLogMsg, sizeof(char), strLogMsg.GetLength(), fpLog);
fflush(fpLog);
fclose(fpLog);
}

你可能感兴趣的:(一行一行写数据到文件中)