Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. CFile and my class

CFile and my class

Scheduled Pinned Locked Moved C / C++ / MFC
helpdebugging
3 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    Ahmad
    wrote on last edited by
    #1

    CFile and my class some problem when I use Cfile to write and read my class I write this class : class omega { public: CString o_str; omega(); virtual ~omega(); }; after that (write work) in functio with button control : void CMyDialog::OnButWrite() { char name[]="mydata.dat"; CFile cfl(name,CFile::modeCreate | CFile::modeWrite); omega om; om.o_str = "OMEGA"; cfl.Write(&om,sizeof(om)); cfl.Close(); } then (read work) in functio with button control : void CMyDialog::OnButRead() { char name[]="mydata.dat"; CFile cfl(name,CFile::modeRead); omega om ; cfl.Read(&om,sizeof(om)); MessageBox(om.om2.o_str,"DATA FROM mydata.dat " ); } now the problem here ... the program was compiled without any errors but in run time , when you do write work and then read work error message apeare and tell me that : that's caused an error in MSVCRTD.DLL then another message apeare and tell me that : Debug Assertion Failed! FILE:dbgheap.c LINE:1017 Expression : _BLOCK_TYPE_IS_VALID(pHead->nBlockUse) this problem is apeare when I use CString in my calss and didn't apear when I use base types like char,int...etc any one can helpe me... AHMAD ALWASHALI

    A M 2 Replies Last reply
    0
    • A Ahmad

      CFile and my class some problem when I use Cfile to write and read my class I write this class : class omega { public: CString o_str; omega(); virtual ~omega(); }; after that (write work) in functio with button control : void CMyDialog::OnButWrite() { char name[]="mydata.dat"; CFile cfl(name,CFile::modeCreate | CFile::modeWrite); omega om; om.o_str = "OMEGA"; cfl.Write(&om,sizeof(om)); cfl.Close(); } then (read work) in functio with button control : void CMyDialog::OnButRead() { char name[]="mydata.dat"; CFile cfl(name,CFile::modeRead); omega om ; cfl.Read(&om,sizeof(om)); MessageBox(om.om2.o_str,"DATA FROM mydata.dat " ); } now the problem here ... the program was compiled without any errors but in run time , when you do write work and then read work error message apeare and tell me that : that's caused an error in MSVCRTD.DLL then another message apeare and tell me that : Debug Assertion Failed! FILE:dbgheap.c LINE:1017 Expression : _BLOCK_TYPE_IS_VALID(pHead->nBlockUse) this problem is apeare when I use CString in my calss and didn't apear when I use base types like char,int...etc any one can helpe me... AHMAD ALWASHALI

      A Offline
      A Offline
      AlexMarbus
      wrote on last edited by
      #2

      Why don't you use a CArchive to read/write from/to your class? You can easily use WriteString then (be sure to add a newline while writing to a CArchive) See MSDN Library, topic CArchive (and Serialize) for more info. -- Alex Marbus www.marbus.net But then again, I could be wrong.

      1 Reply Last reply
      0
      • A Ahmad

        CFile and my class some problem when I use Cfile to write and read my class I write this class : class omega { public: CString o_str; omega(); virtual ~omega(); }; after that (write work) in functio with button control : void CMyDialog::OnButWrite() { char name[]="mydata.dat"; CFile cfl(name,CFile::modeCreate | CFile::modeWrite); omega om; om.o_str = "OMEGA"; cfl.Write(&om,sizeof(om)); cfl.Close(); } then (read work) in functio with button control : void CMyDialog::OnButRead() { char name[]="mydata.dat"; CFile cfl(name,CFile::modeRead); omega om ; cfl.Read(&om,sizeof(om)); MessageBox(om.om2.o_str,"DATA FROM mydata.dat " ); } now the problem here ... the program was compiled without any errors but in run time , when you do write work and then read work error message apeare and tell me that : that's caused an error in MSVCRTD.DLL then another message apeare and tell me that : Debug Assertion Failed! FILE:dbgheap.c LINE:1017 Expression : _BLOCK_TYPE_IS_VALID(pHead->nBlockUse) this problem is apeare when I use CString in my calss and didn't apear when I use base types like char,int...etc any one can helpe me... AHMAD ALWASHALI

        M Offline
        M Offline
        Michael Dunn
        wrote on last edited by
        #3

        Your problem is that a CString object does not contain the string itself, only a pointer to the string. When you write your omega object to the file, you only write the pointer, which is then invalid when you read the object back in and try to use it. --Mike-- http://home.inreach.com/mdunn/ All your base are belong to ME~!

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups