VC:CFile(向文件读写数据、Edit控件)

 

       CString str="";

       GetDlgItemText(IDC_EDIT1,str);

       CFile file;

       if(!file.Open("test.txt",CFile::modeReadWrite))

              file.Open("test.txt",CFile::modeReadWrite|CFile::modeCreate);

       else

       {

              file.SeekToEnd();

              file.Write(str,str.GetLength());

              SetDlgItemText(IDC_EDIT1,"");

 

              file.SeekToBegin();

              str="";

              char *c;

              c=new char[file.GetLength()+1];

              c[file.GetLength()+1]=0;

              file.Read(c,file.GetLength());

              str=c;

              SetDlgItemText(IDC_EDIT2,str);

       }

posted @ 2012-10-15 21:35  慧由心生  阅读(2539)  评论(0编辑  收藏  举报