C++ It's not reading from the file back into the dynamic struct
<p>so you can adopt a pet (kind of buggy right now since it doesn't read in the value)</p>

<p>In the file i'll see it turn into a 1 from a 0; which means it is true. and therefore it should say adopted.</p>

<p>is this the correct way to read in a bool? The problem is in the read function, my problem is that the </p>

<p>read >> </p>

<pre><code>#include &lt;iostream&gt;
#include &lt;cctype&gt;
#include &lt;cstring&gt;
#include &lt;fstream&gt;
using namespace std;

const int TEMP_SIZE = 250;

struct animal
{
    char *name;
    char *breed;
    float age;
    float weight;
    char *desc;
    bool adopted;
//we generate this
    int ID; 
};

struct family
{
    char *host;
    char *address;
    int numDogs;    
};

class petAdoption
{
    public:
    //petAdoption();
    //~petAdoption();
    void enroll(animal pet[], int &amp; count);
    void read(animal pet[], int &amp; count);
    void display(animal pet[], int &amp; count);
    void adoptPet(animal pet[], int &amp; count);
    void getNum(int &amp; count);
};

void petAdoption::enroll(animal pet[], int &amp; count)
{
//name Dynamic array 1;
    char temp[TEMP_SIZE];
    cout &lt;&lt; "Please your pet's name: ";
    cin.get(temp, TEMP_SIZE);
    cin.ignore(100, '\n');
    pet[count-1].name = new char[strlen(temp)];
    strcpy(pet[count-1].name, temp);
//breed Dynamic array 2;
    cout &lt;&lt; "Please your pet's breed: ";
    cin.get(temp, TEMP_SIZE);
    cin.ignore(100, '\n');
    pet[count-1].breed = new char[strlen(temp)];
    strcpy(pet[count-1].breed, temp);
//desc Dynamic array 3;
    cout &lt;&lt; "Please a desc of your pet: ";
    cin.get(temp, TEMP_SIZE);
    cin.ignore(100, '\n');
    pet[count-1].desc = new char[strlen(temp)];
    strcpy(pet[count-1].desc, temp);
//not adopted 
    pet[count-1].adopted = false;
    ofstream write;

    write.open("pets.txt", ios::app);
        write &lt;&lt; pet[count-1].name &lt;&lt; '\n';
    write.close();
    write.open(pet[count-1].name);
        write &lt;&lt; pet[count-1].name &lt;&lt; '\n'
        &lt;&lt; pet[count-1].breed &lt;&lt; '\n'
        &lt;&lt; pet[count-1].desc &lt;&lt; '\n'
        &lt;&lt; pet[count-1].adopted &lt;&lt; '\n';
    write.close();
}


//This method basically, allocates memory for the array.
void petAdoption::getNum(int &amp; count)
{
    ifstream read;  
    char temp[TEMP_SIZE];
    read.open("pets.txt");
        if(!read)
        {
            cout &lt;&lt; "error 1" &lt;&lt; endl;
            count = 1;
        }
        else{
            while(!read.eof())
            {
                read.getline(temp, TEMP_SIZE);
                count = ++count;
            }
        }
    read.close();
}

void petAdoption::read(animal pet[], int &amp; count)
{
    ifstream read;  
    char temp[TEMP_SIZE];

//read in the names
    int k = 0;
    read.open("pets.txt");
    if(!read)
    {
        cout &lt;&lt; "There's No pets.txt file! (Ignore this!)" &lt;&lt;endl;
    }
    else 
    {
        while(!read.eof())
        {
            read.getline(temp, TEMP_SIZE);
            pet[k].name = new char[strlen(temp)+1];
            strcpy(pet[k].name, temp);
        ++k;
        }
    }
    read.close();




    for (int i = 0; i &lt; count-1; ++i)
    {
        read.open(pet[i].name);
            if(!read)
            {
                cout &lt;&lt; "error 2" &lt;&lt; endl;
            }
            else{
                while(!read.eof())
                {
        //name
                    read.getline(temp, TEMP_SIZE);
                    pet[i].name = new char[strlen(temp)+1];
                    strcpy(pet[i].name, temp);
        //breed
                    read.getline(temp, TEMP_SIZE);
                    pet[i].breed = new char[strlen(temp)+1];
                    strcpy(pet[i].breed, temp);
        //desc
                    read.getline(temp, TEMP_SIZE);
                    read.ignore(100, '\n');
                    pet[i].desc = new char[strlen(temp)+1];
                    strcpy(pet[i].desc, temp);

                    read &gt;&gt; pet[i].adopted;
                cout &lt;&lt; i &lt;&lt; endl;
                }
            }
        read.close();
    }
}

void petAdoption::display(animal pet[], int &amp; count)
{
    for (int i = 0; i &lt; count-1; ++i){
        cout &lt;&lt; "Pet id = " &lt;&lt; i &lt;&lt; '\n' &lt;&lt; endl;
        cout &lt;&lt; pet[i].name &lt;&lt; '\n' &lt;&lt; pet[i].breed &lt;&lt; '\n' &lt;&lt; pet[i].desc &lt;&lt; '\n';
        cout &lt;&lt; pet[i].adopted &lt;&lt; endl;
        if (pet[i].adopted == false){
            cout &lt;&lt; "Not adopted" &lt;&lt; '\n' &lt;&lt; endl;
        }
        if (pet[i].adopted == true){
            cout &lt;&lt; "Adopted" &lt;&lt; '\n' &lt;&lt; endl;
        }
    }
}

void petAdoption::adoptPet(animal pet[], int &amp; count)
{   
    int adoptID;
    cout &lt;&lt; "Which pet would you like to adopt? (Please enter the ID, EG: 2 or 5): ";
    cin &gt;&gt; adoptID;
    cin.ignore(100, '\n');

    pet[adoptID].adopted = true;
    cout &lt;&lt; pet[adoptID].adopted &lt;&lt; endl;

    ofstream write;
    for (int i = 0; i &lt; count; ++i){
        write.open(pet[i].name);
            write &lt;&lt; pet[i].name &lt;&lt; '\n'
            &lt;&lt; pet[i].breed &lt;&lt; '\n'
            &lt;&lt; pet[i].desc &lt;&lt; '\n'
            &lt;&lt; pet[i].adopted &lt;&lt; '\n';
        write.close();
    }
}

int main()
{
//When starting the program, we read in from the text files first
//and then we count how many animals we have had in the shelter
//and we use that as a base to dynamically allocate the structs 
    petAdoption adopt;
    char again;
    int choice;
    do {
        int count = 0;
        adopt.getNum(count);
        animal *pet;
        pet = new animal[count];
        adopt.read(pet, count);
        cout &lt;&lt; "~~~~~~~~~~~~~~~~~~MENU~~~~~~~~~~~~~~~~~~" &lt;&lt; endl;
        cout &lt;&lt; "1) Enroll a pet" &lt;&lt; endl;
        cout &lt;&lt; "2) Display pets" &lt;&lt; endl;
        cout &lt;&lt; "3) Adopt a pet" &lt;&lt; endl;
        cout &lt;&lt; "Please make your selection (1-3): ";
        cin &gt;&gt; choice;
        cin.ignore(100,'\n');
        if (1 == choice){
            adopt.read(pet, count);
            adopt.enroll(pet, count);
        }
        if (2 == choice){
            adopt.read(pet, count);
            adopt.display(pet, count);
        }
        if (3 == choice){
            adopt.read(pet, count);
            adopt.adoptPet(pet, count);
        }
        cout &lt;&lt; "Would you like to try again? (y/n): ";
        cin &gt;&gt; again;
        cin.ignore(100,'\n');
    } while ('Y' == toupper(again)); 
}
</code></pre>
