你知道MFC如何在文件尾追加數據嗎?相信很多小伙伴們對于MFC在文件尾追加數據的方法都很有興趣,那么下面我們就一起跟小編去看看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如何在文件尾追加數據的內容,文中還涉及了一些涉及MFC文件操作的相關技巧,希望對大家的學習有所幫助。
新聞熱點
疑難解答
圖片精選