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 nad struct

CFile nad struct

Scheduled Pinned Locked Moved C / C++ / MFC
question
4 Posts 4 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
    ALTF4
    wrote on last edited by
    #1

    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---\\\

    B R D 3 Replies Last reply
    0
    • A ALTF4

      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---\\\

      B Offline
      B Offline
      Blake V Miller
      wrote on last edited by
      #2

      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 out sizeof(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.

      1 Reply Last reply
      0
      • A ALTF4

        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---\\\

        R Offline
        R Offline
        Ravi Bhavnani
        wrote on last edited by
        #3

        This[^] series of articles may help. /ravi My new year's resolution: 2048 x 1536 Home | Articles | Freeware | Music ravib@ravib.com

        1 Reply Last reply
        0
        • A ALTF4

          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---\\\

          D Offline
          D Offline
          David Crow
          wrote on last edited by
          #4

          ALTF4 wrote: f.Write(&x,sizeof(naslovnik));///this is the porblem Had you serialized naslovniki instead of using Write(), it would have worked.


          "Ideas are a dime a dozen. People who put them into action are priceless." - Unknown

          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