Whats wrong with this code.
I can create the DAT file.Name and Grade is writing to the file perfectly.
but the file contains ASCII values for RollNO and after Grade.
Output file:
Name A ÈB
Program:
#include<iostream.h>
#include<conio.h>
#include<fstream.h>
#include<string.h>
class stu
{
int rollno;
char name[20];
char grade;
float marks;
public:
void getdata(void)
{
cout<<"enter the roll no\n";
cin>>rollno;
cout<<"enter the name\n";
cin>>name;
cout<<"enter the marks\n";
cin>>marks;
if(marks>=75) grade='A';
else if(marks>=60) grade='B';
else if(marks>=50) grade='C';
else if(marks>=40) grade='D';
else grade='F';
}
void putdata(void)
{
cout<<"RollNo\n"<<rollno;
cout<<"\n Name\n"<<name;
cout<<"\n Marks\n"<<marks;
cout<<"\n Grade\n"<<grade;
}
}s1;
void main()
{
clrscr();
fstream filin;
ofstream filout;
filout.open("test1.dat",ios::out);
{
s1.getdata();
filout.write((char*)&s1,sizeof(s1));
s1.putdata();
filin.read((char*)&s1,sizeof(s1));
}
filin.close();
filout.close();
getch();
}