Click here to Skip to main content
Licence CPOL
First Posted 9 Nov 2000
Views 57,145
Bookmarked 17 times

Serializing Data to / from an ASCII-file

By Thomas Blenkers | 9 Nov 2000
A series of articles that resulted from experimenting with adding Drag and Drop features to my existing application.
1 vote, 50.0%
1

2
1 vote, 50.0%
3

4

5
3.33/5 - 8 votes
μ 3.33, σa 2.47 [?]

This article is part of the drag and drop interface samples.

  1. Serializing ASCII Data
  2. Modeless child dialog
  3. Modeless sibling dialog
  4. The drag source
  5. The MFC drop target
  6. The TBTextTarget class

  • Download source files - 24 Kb

    Preface

    The CArchive object has methods called ReadString and WriteString. ReadString reads a complete line stopping at, but not including the Carriage return/Line feed pair. WriteString puts the specified string value into the archive, but without the CR/LF. ReadString detects EOF by a returning zero which can be used in a while-conditional.

    This is from the sample application, step zero:

    void CInterfaceDoc::Serialize(CArchive& ar)
    {
        <font color="#000080">if</font> (ar.IsStoring())
        {
            for (int i=0; i<m_String.GetUpperBound(); i++)
                ar.WriteString(m_Strings[i]+"\n");
        }
        <font color="#000080">else</font>
        {
            m_Strings.RemoveAll();
    
            int idx=0;
            CString t;
    
            TRY
            {
                <font color="#000080">while</font>(ar.ReadString(t))
                {
                    m_Strings.SetAtGrow(idx, t);
                    idx++;
                }
            }
            CATCH(CArchiveException, e)
            {
    <font color="#000080">#ifdef</font> _DEBUG
                TCHAR szCause[255];
                CString strFormatted;
                e->GetErrorMessage(szCause, 255);
    <font color="#008000">            // in real life, it's probably more
                // appropriate to read this from
                // a string resource so it would be easy to
                // localize</font>
                strFormatted = _T("CArciveException: ");
                strFormatted += szCause;
                AfxMessageBox(strFormatted); 
    <font color="#000080">#endif </font><font color="#008000">//_DEBUG</font>
            }
            END_CATCH;
    
            UpdateAllViews(NULL);
        }
    }
    
  • License

    This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

    About the Author

    Thomas Blenkers

    Web Developer

    Germany Germany

    Member
    PhD Chemist,
    programming with MSVC & MFC since 1996

    Sign Up to vote   Poor Excellent
    Add a reason or comment to your vote: x
    Votes of 3 or less require a comment

    Comments and Discussions

     
    You must Sign In to use this message board. (secure sign-in)
     
    Search this forum  
     FAQ
        Noise  Layout  Per page   
      Refresh
    Generalhiiiii question! PinmemberArsineh Boodaghian8:16 26 Apr '09  
    AnswerRe: hiiiii question! PinmemberThomas Blenkers10:07 26 Apr '09  

    General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

    Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

    Permalink | Advertise | Privacy | Mobile
    Web02 | 2.5.120210.1 | Last Updated 10 Nov 2000
    Article Copyright 2000 by Thomas Blenkers
    Everything else Copyright © CodeProject, 1999-2012
    Terms of Use
    Layout: fixed | fluid