CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Guest

    Storing Tables in Files

    Hi,

    can anyone recommend an efficient method for storing a tab or comma delimited table in a file. Preferably I would like to save the file as a DAT file. Any suggestions would be greatly appreciated,

    Daniel


  2. #2
    Join Date
    May 1999
    Location
    Farnborough, Hants, England
    Posts
    710

    Re: Storing Tables in Files

    When you say DAT file, do you mean human-readable? If so, use CStdioFile and use its ReadString() and WriteString() methods to manipulate each line of the table (or each element, if you prefer). If you don't need it readable, you can Serialize() the table by making a CString of each line (or element) and using the insert operators (<< and >&gt to serialize each CString.

    Is this what you wanted to know?



    --
    Jason Teagle
    [email protected]

  3. #3
    Join Date
    Apr 1999
    Posts
    383

    Re: Storing Tables in Files

    If you put your lines of table data into a standard library vector or list, it's easy:

    #include <vector>
    #include <fstream>
    #include <algorithm>
    #include <string>
    using namespace std;

    vector<string> myTable; // array of strings for table

    // fill myTable with strings here

    ofstream outFile("MyFile.DAT"); // Open output file stream

    // Copy myTable to outFile
    copy(myTable.begin(), myTable.end(), ostream_iterator<string>(outFile));

    if (!outFile.good())
    {
    // Handle errors here
    }



    Dave



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