Reading object from file in C++ using Read function

Report
Question

Please briefly explain why you feel this question should be reported .

Report
Cancel

void fileRead()
{
student s22;
fstream out;
out.open(“ABC.txt”,ios::in);
while(!out.eof())
{
out.read((char *)&s22,sizeof(s22));
cout<<s22.roll_no<<“\t”<<s22.name<<“\t\t”<<s22.marks<<“\t”<<endl;
}
}
When I try to read object from file using read function in C++ then it return last record 2 times.

Output like this:
11 Ram 70
12 Mohan 80
12 Mohan 80

Please help me to solve this

0
C++ 2 months 0 Answer 257 views 0

Leave an answer

Browse

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>