void input()
{
cout<<"enter name : \n";
cin>>name;
cout<<"enter roll no. pls : \n";
cin>>roll;
cout<<"\nmarks of first subject : ";
cin>>mark1;
cout<<"\nmarks of second subject : ";
cin>>mark2;
cout<<"\nmarks of third subject : ";
cin>>mark3;
calc();
};
void calc()
{
int percent = (mark1+mark2+mark3)/3 ;
if(percent<50)
grade='E';
else if ((percent>=50)&&(percent<60))
grade = 'D';
else if ((percent>=60)&&(percent<75))
grade = 'C';
else if ((percent>=75)&&(percent<90))
grade = 'B';
else if ((percent>=90)&&(percent<100))
grade = 'A';
};
void display()
{
student d;
fstream f;
f.open("student.txt",ios::out);
f.read((char*)&d,sizeof(d));
while(f)
{
cout<<"\n your name is : "<<d.name;
cout<<"\n your roll no. is : "<<d.roll;
It works for me.
Post full code after you changed it.
Problem is that fil is non-static class member function. It shoulbe called like:
1 2
student someStudent; //
someStudent.display();
What compiler do you use? Your code didn't work for me untill I included <iostream>, deleted .h from fstream and placed using namespace std; or just added std to everything.