You'll have to memset the struct if you want it to be readable by humans(in which case it probably shouldn't be written to using fstream::write()) as unintialised arrays on the stack will contain junk and close the write file before reading. This might work -
Code:
struct person
{
char lastName[15];
char firstName[15];
int age;
};
int main(int argc, char* argv[])
{
ofstream personOut("nameAge.txt",ios::binary);
if (!personOut) {cout << "Error!";}
person id = {"unassigned", "", 0};
person blank = {" ", "", 0};
for (int i = 0; i < 100; i++)
personOut.write((char *)&id, sizeof(person));
// 14.11.b Enter records sequentially
int numOfRec;
cout << "\nEnter number of records to enter: ";
cin >> numOfRec;
for (int j = 0; j < numOfRec; j++)
{
memset(&id,0,sizeof(person));
cout << "\nEnter last name, first name and age: ";
cin >> id.lastName >> id.firstName >> id.age;
personOut.seekp(j * sizeof(person));
personOut.write((char *)&id, sizeof(person));
}
personOut.close();
ifstream personIn("nameAge.txt",ios::binary);
for(int k =0;k<numOfRec;k++)
{
personIn.seekg(k * sizeof(person));
personIn.read((char *)&id, sizeof(person));
cout << id.lastName << " "<< id.firstName << " "<< id.age << endl;
}
return 0;
}