C/C++ Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 
Go Back   Dev Articles Community ForumsProgrammingC/C++ Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
  #1  
Old December 21st, 2004, 11:10 AM
db-programmer db-programmer is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Dec 2004
Posts: 2 db-programmer User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
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

Reply With Quote
  #2  
Old December 23rd, 2004, 01:05 PM
db-programmer db-programmer is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Dec 2004
Posts: 2 db-programmer User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
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.

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsProgrammingC/C++ Help > Reading/writing files with arrays of objects


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 4 hosted by Hostway