CString str="";
GetDlgItemText(IDC_EDIT1,str);//得到编辑框内容
CFile file;
file.Open("test",CFile::modeReadWrite);//打开文件
file.SeekToEnd();//文件指针到文件末尾
file.Write(str,str.GetLength());//写入文件
    SetDlgItemText(IDC_EDIT1," ");
    file.SeekToBegin();//文件的开始
str=" ";
    char *c;
c=new char[file.GetLength()];//得到文件主长度
file.Read(c,file.GetLength());//读出数据
str=c;
SetDlgItemText(IDC_EDIT2,str);
编辑,链接,执行没问题,可是我一在EDIT1中输入数据时,按确定就出错。 以上是确定按钮的代码。
错误是:Debug Assertion Failde!
        File:filecore.cpp
For information on how your program can cause an assertion failure ,see the Visual C++ documentation onasserts.   
我是新手,问题也许很幼稚大家多帮忙。帮我看看怎么改 ,哪里的问题

解决方案 »

  1.   

    在最下面加一行 file.Close();
      

  2.   

    在最下面加一行  file.Close();
      

  3.   

    单步调试一下看哪里出错了吧
    最笨的方法是在每一行代码下都加上MessageBox提示信息,看执行了多少个 MessageBox就知道代码运行到哪步出错了
      

  4.   

    str=c;
    SetDlgItemText(IDC_EDIT2,str);改成
    str.Format("%s", c);
    SetDlgItemText(IDC_EDIT2,str);试试
      

  5.   

    char *c;
    c=new char[file.GetLength()];//得到文件主长度
    file.Read(c,file.GetLength());//读出数据
    str=c;
    SetDlgItemText(IDC_EDIT2,str);
    ->
    DWORD len = file.GetLength();
    char* c = new char[len+1];
    memset(c, 0, sizeof(char)*(len+1));
    file.Read(c, len);
    str.Format("%s", c);
    SetDlgItemText(IDC_EDIT2, str);
    file.Close();
    delete[] c;
    c = NULL;
      

  6.   

    楼上说的方法我都试过了,但是程序运行以后还是出错,功能是EDIT1内容在按确定后在EDIT2上显示,怎么调都不成