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
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:\\");

            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

    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:\\");
         addressNum = 0;
       .... etcetera...

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

    Author Comment

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

    Featured Post

    What Should I Do With This Threat Intelligence?

    Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

    Join & Write a Comment

    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++ ( I described how to encrypt text and recommended that the encrypted text be stored as a series of hexadecimal digits -- because cyphertext may…
    Migrating to Microsoft Office 365 is becoming increasingly popular for organizations both large and small. If you have made the leap to Microsoft’s cloud platform, you know that you will need to create a corporate email signature for your Office 365…
    Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…

    746 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

    Need Help in Real-Time?

    Connect with top rated Experts

    14 Experts available now in Live!

    Get 1:1 Help Now