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

Thread: Reading a .dat file content to a struct

  1. #1
    Join Date
    Jul 2008

    Reading a .dat file content to a struct

    i am starting to do a simple file I/O program and i was wondering how do i read the .dat file and put the content into the struct i created so that i can manipulate them later. Here is the code i had..
    struct food
            char itemName[50];
    	double price;
    	int sold;
    int main()
    	food Bill[5];
    	ifstream inFile;
    	readFile (inFile, "Billing.dat", Bill);
    void readFile (ifstream& inFile, char fileName[], food Bill[])
    	 inFile.open (fileName);
    	 if (!inFile)
                     cout << "Error: unable to open " << fileName <<endl;
         //reading the content into the struct Bill
    the .dat file content 2 lines, they are:

    Bacon Sausgae Eggs Coffee Tea
    1.50 1.20 .140 .130 .180

    i created 5 records, which correspond to the 5 items in the . dat file.

    Note: sorry for missing out

    so as i said, i would like to read those content in the .dat and store to the struct i had created, so later on, i can use that information to do some simple mathamatic. Because i had a menu with options to let user to select
    Last edited by xiaolim; April 21st, 2009 at 05:46 AM. Reason: Miss out some point~ sorry

  2. #2
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Hanover Germany

    Re: Reading a .dat file content to a struct

    And what?
    Victor Nijegorodov

Posting Permissions

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

Windows Mobile Development Center

Click Here to Expand Forum to Full Width

On-Demand Webinars (sponsored)