error in rewrite CDocment::Serialize()

void CmyPainterDoc::Serialize(CArchive& ar)
{

 if (ar.IsStoring())
 {
   CFile mfile=ar.GetFile();
  char buf[100]="this should be ok!";
  mfile.Seek(0L, CFile::begin);
  mfile.Write(buf,sizeof(buf));

~~~

when i wana save a file as 111.tmp, whether it already exists or not,  this error occur:

"cannot find file 111.tmp"

why



Answer this question

error in rewrite CDocment::Serialize()

  • Frank Roberts

    This code must be invalid:
    CFile mfile=ar.GetFile();
    GetFile returns a pointer.

    Also why you are not using the standard << operator of the CArchive object
    Also repsoitioning the file pointer in an archive may lead in an unexpected beahaviour. Just use the stream as it is.


  • error in rewrite CDocment::Serialize()