想把一个串写入文件,单击按钮后实现,但是每次只能按一次,按第二次就出错了,只能重新运行程序,请问有什么办法实现吗?相关的代码如下:
char UserLoginSet::UserWriteFile(char Data[],int len)

    try
{
file.Open("e:/aa.acc",CFile::modeCreate|CFile::modeNoTruncate|CFile::modeWrite);
    file.SeekToEnd();
  file.Write(Data,len);
file.Flush();
file.Close;
}
catch (CFileException *e)
{
CString str;
str.Format("error:%d",e->m_cause);
MessageBox("str");
file.Abort();
e->Delete();
}
return(TRUE);
}
//---------------------------------------
void UserLoginSet::OnAdd() 
{
//----get data---
    char StrData[256]="";
char mlogin[20]="";
char mpass[16]="";
m_Mlogin.GetWindowText(mlogin,sizeof(mlogin)-1);
m_Mpassword.GetWindowText(mpass,sizeof(mpass)-1);
if((strcmp(mlogin,"")==0) ||(strcmp(mpass,"")==0))
{
AfxMessageBox("error");
return;
}
//--------------
strcat(StrData,mlogin);
strcat(StrData,"/");
strcat(StrData,mpass);
strcat(StrData,"\r\n");
int lennum=strlen(StrData);
//--------------
UserWriteFile(StrData,lennum);
}