First off, this is for a class, I'm really trying to learn this and be able to do it on my own but when a hang up occurs and you only have 24 hours to finish it one must take drastic actions. So I plead for help from the learned ones...
I want to write the information stored in the 'Pets' array to a file called 'animals.txt...
I know that this code looks really twisted, I'm using a list to automatically populate my data members of the 'Animal' class.
Where am I going wrong?
Code:
//initial code, initialization of data members....
fstream theFile("C:\\Junkdata\\Animals.txt");
//fstream theFile((char *) &Pets, ios::out | ios::app | ios::binary);
if(!theFile)
{
cout << "File object not created...";
return 999;
}
theFile.close();
theFile.open((char *) &Pets, ios::in | ios::binary);
if(theFile.fail())
{
cout << "Unable to open input file....";
return 9999;
}
//Animal generic;
theFile.read((char *) &Pets, sizeof(Animal));
for(int a(0); a < count; a++)
{
theFile.write((char *) &Pets[a++], sizeof(Animal));
if(a = 0)
{
Header();
}
if(a == count)
{
cout << "Total number of animals: " << count << endl;
cout << endl << "David Evans" << endl;
cout << "ITSE-2431.005" << endl;
cout << "May 2nd, 2002" << endl;
}
}
ofstream outFile("C:\\JunkData\\Animals.txt");
if(!outFile)
{
cout << "Unable to open file...";
return 999;
}
return 0;
}
I've excluded the 'Animal' class as I am not having any difficulty with it and did not think it was relevant for the problem that I'm having. Should anybody like to view it I'll post it immediately.
Thanks a lot for any assistance, hints, and clues.