Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

I wanted to change C style fileopen to C++ style using ifstream here is what I d

ID: 3534486 • Letter: I

Question

I wanted to change C style fileopen to C++ style using ifstream

here is what I did, I am keep getting run-time error. Any ideas why?

file = "person.bin";
FILE *fpr;

fpr = fopen(file,"rb");
if(!fpr) {
  cout << "Person.bin FILE DOES NOT EXIST OR DAMAGED." << endl;
  exit(1);
}
fseek(fpr,0L,SEEK_END);
total_block = ftell(fpr) / sizeof(person); // number of members
fseek(fpr,0L,SEEK_SET);
d = (person*)malloc(sizeof(person)*total_block);
fread(d,sizeof(person),total_block,fpr);
fclose(fpr);

-----------------------------------------------------------

fstream fpr("person.bin", ios::in | ios::out | ios::binary);
  if(!fpr) {
  cout << "Person.bin FILE DOES NOT EXIST OR DAMAGED." << endl;
  exit(1);
  }
  fpr.seekp(0, ios::end);
  total_block = (fpr.tellg() / sizeof(person));
  fpr.seekp(0, ios::beg);
  d = new person[sizeof(person) * total_block];
  fpr.read((char *)&d, total_block);
fpr.close();

Explanation / Answer

fstream file; file.open("file.ext",iso::in|ios::out) put like this

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote