CFile and my class
-
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
-
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
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.
-
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
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~!