Thread: read/write Cstring array to file

  1. #1
    bonkey
    Guest

    Question read/write Cstring array to file

    I thought I had this all working. I am trying to store 2 arrays of strings. 1) Persons name 2) Notes This is basically a homemade database of notes.

    For somereason the notes don't load properly.

    Please look at my code and see if you see a problem.

    Code:
    CFile PlayerFile;
    CStringList m_Players;
    CStringList m_Text;
    
    if(PlayerFile.Open("playerinfo.dat",CFile::modeNoTruncate|CFile::modeReadWrite|CFile::shareExclusive,NULL))
    {
    CArchive ar(&PlayerFile, CArchive::load); // Load its contents into a CArchive
    	
    m_Players.Serialize(ar);
    m_Text.Serialize(ar);
    PlayerFile.Close();
    }
    
    
    pos=m_Players.FindIndex(j);
    if( m_Players.GetAt(pos) == Player)
    {
    	pos=m_Text.FindIndex(j);
    	TEXTLINE[i][0]=m_Text.GetAt(pos);
    	found=true;
    	break;
    }
    
    
    PlayerFile.Open("playerinfo.dat",CFile::modeCreate|CFile::modeReadWrite|CFile::shareExclusive,NULL);
    PlayerFile.SeekToBegin();
    
    CArchive ar (&PlayerFile, CArchive::store); // Load its contents into a CArchive
    m_Players.Serialize(ar);
    m_Text.Serialize(ar);
    This is not everything, this is the load segment the read segment then the save segment. I hope this is enough, but I'll be happy to post more as needed.

    This was working, with occasional corruption, but now it appears to be broken all together.

    Thanks in advance for your help.

  2. #2
    Registered User
    Join Date
    Aug 2002
    Posts
    170
    I figured out the writing problem, it was something stupid. I had move some code where it had been loading up the text to be copied into the notes. I fixed that.

    Any idea's on the corruption issue? The Names are not lost only the text CStringList is lost.
    Best Regards,

    Bonkey

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. disposing error
    By dropper166 in forum C# Programming
    Replies: 2
    Last Post: 03-30-2009, 11:53 PM
  2. opening empty file causes access violation
    By trevordunstan in forum C Programming
    Replies: 10
    Last Post: 10-21-2008, 11:19 PM
  3. Problem with file and array
    By paok in forum C Programming
    Replies: 5
    Last Post: 05-01-2008, 04:19 AM
  4. Can we have vector of vector?
    By ketu1 in forum C++ Programming
    Replies: 24
    Last Post: 01-03-2008, 05:02 AM
  5. Help with CString class and operator+ overloading
    By skanxalot in forum C++ Programming
    Replies: 2
    Last Post: 10-07-2003, 10:23 AM