Попробуйте
while(ifs.read((char *)&two, sizeof(two)))
вместо
while(!(ifs.eof()))
Также попробуйте отформатировать код:)
#include <fstream>
#include <iostream>
using namespace std;
class Student
{
public:
char FullName[40];
char CompleteAddress[120];
char Gender;
double Age;
bool LivesInASingleParentHome;
};
int main()
{
/*Student one;
strcpy(one.FullName, "Ernestine Waller");
strcpy(one.CompleteAddress, "824 Larson Drv, Silver Spring, MD 20910");
one.Gender = 'F';
one.Age = 16.50;
one.LivesInASingleParentHome = true;
ofstream ofs("fifthgrade.ros", ios::binary);
ofs.write((char *)&one, sizeof(one));
Student three;
strcpy(three.FullName, "three Waller");
strcpy(three.CompleteAddress, "three 824 Larson Drv, Silver Spring, MD 20910");
three.Gender = 'M';
three.Age = 17;
three.LivesInASingleParentHome = true;
//ofstream ofs("fifthgrade.ros", ios::binary);
ofs.write((char *)&three, sizeof(three));*/
Student two;
ifstream ifs("fifthgrade.ros", ios::binary);
while(ifs.read((char *)&two, sizeof(two)))
{
cout << "Student Information\n";
cout << "Student Name: " << two.FullName << endl;
cout << "Address: " << two.CompleteAddress << endl;
if( two.Gender == 'f' || two.Gender == 'F' )
cout << "Gender: Female" << endl;
else if( two.Gender == 'm' || two.Gender == 'M' )
cout << "Gender: Male" << endl;
else
cout << "Gender: Unknown" << endl;
cout << "Age: " << two.Age << endl;
if( two.LivesInASingleParentHome == true )
cout << "Lives in a single parent home" << endl;
else
cout << "Doesn't live in a single parent home" << endl;
cout << "\n";
}
return 0;
}