| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
Reading/writing files with arrays of objects
I'm writing a small database program and have come across a problem I can't seem to get round. What I've done so far:
Developed a base class (called Person) to store data about a group of people. Written public methods to get and set the data, which is stored in the base class as private variables. Created 3 derived classes (Person1, Person2, Person3) of the base class (Person), using public inheritence. Written constructors and destructors for all of the above classes. I know how to create an array of objects for a class, e.g. Person1 p1[3] creates an array of 3 objects of the Person1 class? I need to: 1. Enter data using the keyboard and store it in the arrays using the constructors I've written. 2. Read the data back from the files into the program. I have no idea how to do the 2 above things. Especially for the second part, I don't know where the data in the file should be brought back to - is it the array created as shown above (Person1 p1[3]) or a totally different array, or something else? I have only been programming a short time so would appreciate any advice. Thanks, DBP |
|
#2
|
|||
|
|||
|
Okay I managed to sort this out myself, by doing a lot of reading....
Used setw() so data in the file all had a set length. Used seekp() to access the data when reading it back from the file into an array. Used "new" and "delete" to dynamically allocate memory to arrays so that the program didn't run out of memory. I would explain it further, but as nobody replied to the original message I won't bother. |
![]() |
| Viewing: Dev Articles Community Forums > Programming > C/C++ Help > Reading/writing files with arrays of objects |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|