This will work. I don't know how to do it using c++ streams though. You have to open the file in binary mode and read a chunk of data the size of your structure. If you pass fread() a pointer to your structure it will populate your structure (assuming the file has the correct format).
Code:
int main(int argc, char *argv[])
{
FILE * sFile;
struct data student[10];
if (NULL == (sFile = fopen("student.data", "rb")))
{
cout << "Could not open file" << endl;
system("PAUSE");
return -1;
}
cout << "name\tsex\tage\tweight:" << endl;
for (int i=0; i<10; i++)
{
fread(&student[i], sizeof(data), 1, sFile);
cout << student[i].name << "\t";
student[i].MF?(cout << "female\t"):(cout << "male\t");
cout << student[i].age << "\t" << student[i].weight << endl;
}
system("PAUSE");
return EXIT_SUCCESS;
}
kyle