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
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.