MFC实现编辑框写功能程序异常
【求助】MFC实现编辑框写功能程序错误
MFC实现编辑框写功能,程序如下:
void CTest08Dlg::OnBtnWriteFile()
{
// TODO: Add your control notification handler code here
CFileDialog Filedlg(FALSE,"All file","*.*",OFN_HIDEREADONLY,"All File(*.*)");
Filedlg.m_ofn.lpstrTitle="写文件";
CString m_strFileName;
CString m_strFileExm;
CString M_strFileData;
CFile cFile;
CFileException e;
unsigned long lSize;
if (Filedlg.DoModal()!=IDOK)
{
return;
}
else
{
m_strFileName=Filedlg.GetPathName();
m_strFileExm=Filedlg.GetFileExt();
if (cFile.Open(m_strFileName,CFile::modeCreate|CFile::modeWrite,&e))
{
m_ctrFileData.GetWindowText(M_strFileData);
lSize=M_strFileData.GetLength();
char *pBuf=new char[lSize+1];
if (!pBuf)
{
cFile.Close();
return;
}
else
{
strcpy(pBuf,(char*)(LPCSTR)M_strFileData);
*(pBuf+lSize)='\0';
cFile.WriteHuge(pBuf,lSize);
m_ctrFileData.SetWindowText(pBuf);
if (pBuf)
{
DELETE []pBuf;//错误行!!!!!!!!!!!!
}
cFile.Close();
}
}
else
{
TCHAR szCause[255];
CString strFormattted;
e.GetErrorMessage(szCause,255);
strFormattted=_T("The data file could not be read because of this error:");
strFormattted+=szCause;
AfxMessageBox(strFormattted);
return;
}
}
}
在DELETE []pBuf;行提示错误“error C2059: syntax error : ']'”,
请问是何原因?如何解决?
------解决方案--------------------
大小写是有区分的,delete.
#define DELETE (0x00010000L)
------解决方案--------------------
MFC实现编辑框写功能,程序如下:
void CTest08Dlg::OnBtnWriteFile()
{
// TODO: Add your control notification handler code here
CFileDialog Filedlg(FALSE,"All file","*.*",OFN_HIDEREADONLY,"All File(*.*)");
Filedlg.m_ofn.lpstrTitle="写文件";
CString m_strFileName;
CString m_strFileExm;
CString M_strFileData;
CFile cFile;
CFileException e;
unsigned long lSize;
if (Filedlg.DoModal()!=IDOK)
{
return;
}
else
{
m_strFileName=Filedlg.GetPathName();
m_strFileExm=Filedlg.GetFileExt();
if (cFile.Open(m_strFileName,CFile::modeCreate|CFile::modeWrite,&e))
{
m_ctrFileData.GetWindowText(M_strFileData);
lSize=M_strFileData.GetLength();
char *pBuf=new char[lSize+1];
if (!pBuf)
{
cFile.Close();
return;
}
else
{
strcpy(pBuf,(char*)(LPCSTR)M_strFileData);
*(pBuf+lSize)='\0';
cFile.WriteHuge(pBuf,lSize);
m_ctrFileData.SetWindowText(pBuf);
if (pBuf)
{
DELETE []pBuf;//错误行!!!!!!!!!!!!
}
cFile.Close();
}
}
else
{
TCHAR szCause[255];
CString strFormattted;
e.GetErrorMessage(szCause,255);
strFormattted=_T("The data file could not be read because of this error:");
strFormattted+=szCause;
AfxMessageBox(strFormattted);
return;
}
}
}
在DELETE []pBuf;行提示错误“error C2059: syntax error : ']'”,
请问是何原因?如何解决?
------解决方案--------------------
大小写是有区分的,delete.
#define DELETE (0x00010000L)
------解决方案--------------------