CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5
  1. #1
    Join Date
    Feb 2011
    Posts
    39

    Question VC++ File Handling for CString.

    Hello all,

    I am working on a project and i need to save a CString to a file and load it back later. I found out that i could use:

    1.) the CFile method.
    2.) the CArchive method.
    3.) the fstream method.

    What are the various advantages/disadvantages of using any of these methods? Which one should I use for my basic file handling purposes? How do I write a CString to file?

    Thanks a lot in advance.

  2. #2
    GCDEF is offline Elite Member Power Poster
    Join Date
    Nov 2003
    Location
    Florida
    Posts
    12,635

    Re: VC++ File Handling for CString.

    Do you actually need a CString object or just text?

    Archiving is good if you have a complex class structure and need to save and restore it intact. For just a line of text, it's probably not the best approach.

    The easiest method is CStdioFile::WriteString()

  3. #3
    Join Date
    Feb 2011
    Posts
    39

    Re: VC++ File Handling for CString.

    It is actually a custom-made table which has 5 fields to each entry and possibly hundreds of such entries.

    Could CArchive possibly help reduce a great deal of effort? All the entries are contained in a class called CFJTable which may perhaps be saved as one unit.

    My other option is to save each field of each entry into the file, while introducing some character for separation between each field and each entry.

    Thanks for replying, GCDEF.

  4. #4
    GCDEF is offline Elite Member Power Poster
    Join Date
    Nov 2003
    Location
    Florida
    Posts
    12,635

    Re: VC++ File Handling for CString.

    Quote Originally Posted by nitinmalapalli View Post
    It is actually a custom-made table which has 5 fields to each entry and possibly hundreds of such entries.

    Could CArchive possibly help reduce a great deal of effort? All the entries are contained in a class called CFJTable which may perhaps be saved as one unit.

    My other option is to save each field of each entry into the file, while introducing some character for separation between each field and each entry.

    Thanks for replying, GCDEF.
    Sounds like Serialization is what you want then. As long as everything you want to save is derived from CObject, it's pretty easy to use.

  5. #5
    Join Date
    Feb 2011
    Posts
    39

    Re: VC++ File Handling for CString.

    Thanks a lot! I think i can close this thread now. I got all the information i needed. Thanks again.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured