[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now


loading a objects from a file into a class of objects and then putting those objects into 1 block of an array.

Posted on 2005-04-16
Medium Priority
Last Modified: 2010-04-24
THis might be the wrong way to go about this but its whats in my head right now. Ok so I have a file of data and each line of data is going to be a record. Each line has been loaded into a class of objects. Now what I want to do is put all those object into one block of an array, and then load the next line into the class and stick that into the next block of the array and so on. My problem is I'm putting the info thats in the classes into the array. If its not possible to put a buch of info into one block of my array, I'll setting for just putting them into the array.

THis is what I'm thinking but I'm not sure. addressBook1 is my array, the class name is addressInfo (some how I think this hould be included but I'm not sure where.), addressNum is my counter.

void loadBook(addressBook addressBook1[],int &addressNum);
      string stuff;
      ifstream inFile("c:\\myAddresses.data");

            cout<<endl<"THe myAddresses file did not open";

      inFile >>addressBook1[addressNum].gettheAddress;
                inFile >>addressBook1[addressNum].getthecity;  
                 inFile >>addressBook1[addressNum].getthestate;
                 inFile >>addressBook1[addressNum].getthezip;
Question by:stallion5000
LVL 55

Accepted Solution

Jaime Olivares earned 1500 total points
ID: 13799453
This could be possible but I don't see where you initialize addressNum , maybe before calling loadBook ?
Since you open file inside loadBook and start reading from first byte, I suppose will be better to initialize inside load book.

Something like:
void loadBook(addressBook addressBook1[],int &addressNum);
     string stuff;
     ifstream inFile("c:\\myAddresses.data");
     addressNum = 0;
   .... etcetera...

Also, could be a good idea to return addressNum instead of void.

Author Comment

ID: 13799679
I figured it out, but I'll give you the points cause you've been awesome in the past. Thanks!

Featured Post

[Webinar] Cloud and Mobile-First Strategy

Maybe you’ve fully adopted the cloud since the beginning. Or maybe you started with on-prem resources but are pursuing a “cloud and mobile first” strategy. Getting to that end state has its challenges. Discover how to build out a 100% cloud and mobile IT strategy in this webinar.

Question has a verified solution.

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

The following diagram presents a diamond class hierarchy: As depicted, diamond inheritance denotes when two classes (e.g., CDerived1 and CDerived2), separately extending a common base class (e.g., CBase), are sub classed simultaneously by a fourt…
In Easy String Encryption Using CryptoAPI in C++ (http://www.experts-exchange.com/viewArticle.jsp?aid=1193) I described how to encrypt text and recommended that the encrypted text be stored as a series of hexadecimal digits -- because cyphertext may…
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…
In a question here at Experts Exchange (https://www.experts-exchange.com/questions/29062564/Adobe-acrobat-reader-DC.html), a member asked how to create a signature in Adobe Acrobat Reader DC (the free Reader product, not the paid, full Acrobat produ…

868 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