本文實例講述了MFC實現在文件尾追加數據的方法。分享給大家供大家參考。具體如下:
BOOL CDelDlg::WritetoFile(CString sValue){ CString sFile = GetExePath() + "http://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程序設計有所幫助。
新聞熱點
疑難解答
圖片精選