MFC实现在文件尾追加数据的方法_技术学院_宜昌市隼壹珍商贸有限公司

您好,欢迎访问宜昌市隼壹珍商贸有限公司

400 890 5375
当前位置: 主页 > 新闻动态 > 技术学院

MFC实现在文件尾追加数据的方法

发布时间:2026-01-18  |  点击率:

本文实例讲述了MFC实现在文件尾追加数据的方法。分享给大家供大家参考。具体如下:

BOOL CDelDlg::WritetoFile(CString sValue)
{
  CString sFile = GetExePath() + "\\1.log";
  CStdioFile file;
  if(file.Open(sFile, CFile::modeCreate | CFile::modeWrite | CFile::modeNoTruncate))
  {
    file.SeekToEnd(); // 移动文件指针到末尾
    file.WriteString(sValue);
    file.Close();
  }
  return FALSE;
}

其中,GetExePath()代码如下:

// 返回可执行文件所在的目录(不包含最后的'\')
CString GetExePath()
{
  char sFileName[256] = {0};
  CString sPath = _T("");
  GetModuleFileName(AfxGetInstanceHandle(), sFileName, 255);
  sPath.Format("%s", sFileName);
  int pos = sPath.ReverseFind('\\');
  if(pos != -1)
    sPath = sPath.Left(pos);
  else
    sPath = _T("");
  return sPath;
}

希望本文所述对大家的MFC程序设计有所帮助。

全国统一服务电话

400 890 5375

电子邮箱:879577@qq.com

公司地址:宜昌市西陵区黄河路5号三峡明珠10栋1051室

咨询微信

TEL:13680874598