عند الكتابة في ملف عشوائي تكون الأمور على ما يرام .. و عند القراءة من الملف تظهر لي بيانات خاطأة (غير مفهومة ) ..
هذا هو كود الكتابة على الملف
struct student {
int id;
...................
};ofstream outf("std.txt",ios::ate);
if(!outf) {
cerr<<"file not found";
exit(1);
}
outf.seekp ((std.id-1)*sizeof(student),ios::beg);
outf.write ((char *)&std,sizeof(student));
outf.close();و هذا كود القراءة
student std;
ifstream inf("std.txt",ios::in);
if(!inf)
{
cerr<<"(file not found)";
exit(1);
}
inf.seekg((id-1)*sizeof(student),ios::beg);
inf.read ((char *)&std,sizeof(student));أرجو المساعدة
مرفق الملف الذي أعمل به
ملاحظة : أعمل على turbo c++ 4.5 ..
طبعا لا تسألوني لماذا ... هذا هو المطلوب في الواجب