0
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 data 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

I do not understand this problem. Please help me to solve this.

Rohit Chugh
  • 51
  • 1
  • 6

0 Answers0