CFile nad struct
-
how can I save a stuct whit Cfile here is my code but id does not work : struct naslovniki { CString ime1; CString naslov1; CString posta1; CString drzava1; CString naziv1; CString skupina; }; CFile f; f.Open("hasek.has",CFile::modeWrite|CFile::typeBinary); naslovniki x; x.ime1=m_ime; x.naslov1=m_naslov; x.drzava1=m_drzava; x.posta1=m_posta; x.naziv1=m_naziv; x.skupina; f.Write(&x,sizeof(naslovnik));///this is the porblem f.close(); ///---there is no hope for you---\\\
-
how can I save a stuct whit Cfile here is my code but id does not work : struct naslovniki { CString ime1; CString naslov1; CString posta1; CString drzava1; CString naziv1; CString skupina; }; CFile f; f.Open("hasek.has",CFile::modeWrite|CFile::typeBinary); naslovniki x; x.ime1=m_ime; x.naslov1=m_naslov; x.drzava1=m_drzava; x.posta1=m_posta; x.naziv1=m_naziv; x.skupina; f.Write(&x,sizeof(naslovnik));///this is the porblem f.close(); ///---there is no hope for you---\\\
I bet it does work, it just is not doing what you are expecting. If you were to
TRACE("Size of my data is %u bytes.\r\n", sizeof(naslovniki));
I bet your number would be close to 24, and it would not change depending upon what text your CStrings contain. Now, why is this? Because when you write outsizeof(naslovniki)
you are only writing out the contents of the CString class, not its data. In order to write out the text of the CString (unless you are using CArhive), you have to process the data yourself, writing perhaps the length of the text followed by the contents of the text itself. -
how can I save a stuct whit Cfile here is my code but id does not work : struct naslovniki { CString ime1; CString naslov1; CString posta1; CString drzava1; CString naziv1; CString skupina; }; CFile f; f.Open("hasek.has",CFile::modeWrite|CFile::typeBinary); naslovniki x; x.ime1=m_ime; x.naslov1=m_naslov; x.drzava1=m_drzava; x.posta1=m_posta; x.naziv1=m_naziv; x.skupina; f.Write(&x,sizeof(naslovnik));///this is the porblem f.close(); ///---there is no hope for you---\\\
-
how can I save a stuct whit Cfile here is my code but id does not work : struct naslovniki { CString ime1; CString naslov1; CString posta1; CString drzava1; CString naziv1; CString skupina; }; CFile f; f.Open("hasek.has",CFile::modeWrite|CFile::typeBinary); naslovniki x; x.ime1=m_ime; x.naslov1=m_naslov; x.drzava1=m_drzava; x.posta1=m_posta; x.naziv1=m_naziv; x.skupina; f.Write(&x,sizeof(naslovnik));///this is the porblem f.close(); ///---there is no hope for you---\\\
ALTF4 wrote: f.Write(&x,sizeof(naslovnik));///this is the porblem Had you serialized
naslovniki
instead of usingWrite()
, it would have worked.
"Ideas are a dime a dozen. People who put them into action are priceless." - Unknown