?
Solved

Saving structures to files

Posted on 2000-04-11
5
Medium Priority
?
201 Views
Last Modified: 2010-04-02
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!!!
0
Comment
Question by:anita177
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
5 Comments
 
LVL 22

Accepted Solution

by:
nietod earned 50 total points
ID: 2703213
it woudl help if youy posted the code....

since you want the structure in text, not binary, format, you will have to write out each data member individually and converted to an ASCII format.

You can use a fstream object to help you do this as it will do the conversion to ASCII and write the information in onse step.

example follows
0
 
LVL 22

Expert Comment

by:nietod
ID: 2703227
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.)
0
 

Author Comment

by:anita177
ID: 2703718
Ok....

I've read the d
0
 
LVL 22

Expert Comment

by:nietod
ID: 2703737
Huh?    Is there a problem?
0
 
LVL 7

Expert Comment

by:KangaRoo
ID: 2703941
Why the low grade??
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In days of old, returning something by value from a function in C++ was necessarily avoided because it would, invariably, involve one or even two copies of the object being created and potentially costly calls to a copy-constructor and destructor. A…
C++ Properties One feature missing from standard C++ that you will find in many other Object Oriented Programming languages is something called a Property (http://www.experts-exchange.com/Programming/Languages/CPP/A_3912-Object-Properties-in-C.ht…
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.
Suggested Courses

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question