Link to home
Start Free TrialLog in
Avatar of anita177
anita177

asked on

Saving structures to files

Helloo..

I'm doing a project and i have assigned various values to structure members in my main program.. i wanted to know how i could transfer the data values from the structure into a text file for read and write operations.

In the main program the data is read in to the structure using an array.. so i want to pass the value each time to the seperate file before the end of the loop is reached...

I hope this makes sense and you can help!!!
ASKER CERTIFIED SOLUTION
Avatar of nietod
nietod

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of nietod
nietod

since I don't know what information you have to write out, I'll make up a structure like

struct Data
{
    int i;
    double d;
    char c[10];
};


you would write the file like

fstream Fil("C:\\SOMENAME.TXT",ios::out);
Data D = ????;

Fil << D.i << ' ' << D.d << ' ' << D.c << endl;

Then you could read it like

fstream Fil("C:\SOMEFILE.TXT,ios::in);
Data D;

Fil >> D.i >> D.d >> D.c;

Let me know if you have any questions.   (I'll probably need more details from you though.)
Avatar of anita177

ASKER

Ok....

I've read the d
Huh?    Is there a problem?
Why the low grade??