MFC實現在文件尾追加數據的方法
更新時間:2015年09月28日 17:42:13 作者:清清飛揚
這篇文章主要介紹了MFC實現在文件尾追加數據的方法,涉及MFC文件操作的相關技巧,具有一定參考借鑒價值,需要的朋友可以參考下
本文實例講述了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()代碼如下:
// 返回可執(zhí)行文件所在的目錄(不包含最后的'\')
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程序設計有所幫助。
您可能感興趣的文章:
相關文章
探討:C++實現鏈式二叉樹(用非遞歸方式先序,中序,后序遍歷二叉樹)
本篇文章是對用C++實現鏈式二叉樹(用非遞歸方式先序,中序,后序遍歷二叉樹)的方法進行了詳細的分析介紹,需要的朋友參考下2013-05-05

