文件操作

1.写文本文件

void WriteLog(CString strFileName, CString strText)
{
 //判断是否打印日志文件
 if ( g_PrintLogFile != 1)
  return;

 try
 {
  CTime tm = CTime::GetCurrentTime();
  CString strTime = tm.Format(_T("%Y-%m-%d %H:%M:%S"));
  //BOOL bFull = FALSE;
  CStdioFile file;
  if( file.Open(strFileName, CFile::modeCreate | CFile::modeNoTruncate | CFile::modeReadWrite) != 0)
  {
   file.SeekToEnd();
   file.WriteString(strTime);
   file.WriteString(strText);
   file.WriteString(_T("\n\n"));
   //if(file.GetLength() > 2000000)
   // bFull = TRUE;
   file.Close();
  }
  /*
  if(!bFull) return;
  if( file.Open(strFileName, CFile::modeCreate|CFile::modeReadWrite) != 0)
  {
  file.SeekToEnd();
  file.WriteString(strTime);
  file.WriteString(strText);
  file.WriteString(_T("\n"));
  file.Close();
  }
  */
 }
 catch(...)
 {
 }
}

你可能感兴趣的:(文件操作)