Accept Data
Accept Data
#include <fstream>
#include <string>
#include <iomanip>
using namespace std;
struct Student {
int Sno;
string Student_Id;
string First_Name;
string Father_Name;
string G_Father_Name;
string Sex;
string dept;
int Mid;
int final;
string Grade;
}s;
int main()
{
//clrscr();
char filename[15];
ofstream outdata;
cout<<"\nenter file name : ";
cin>>filename;
outdata.open(filename,ios::out);
if(outdata.fail())
{
cerr<<"\nError opening "<<filename;
//getch();
//exit(1);
}
//stud_info student;
//accept data here
cout<<"\nEnter student role number : ";
cin>>s.Sno;
cout<<"\nEnter student ID : ";
cin>>s.Student_Id;
cout<<"\nEnter student Fname : ";
cin>>s.First_Name;
cout<<"\nEnter student father name : ";
cin>>s.Father_Name;
cout<<"\nEnter student G.father name : ";
cin>>s.G_Father_Name;
cout<<"\nEnter student Sex : ";
cin>>s.Sex;
cout<<"\nEnter student department : ";
cin>>s.dept;
cout<<"\nEnter student Mid(40%) : ";
cin>>s.Mid;
cout<<"\nEnter student final(60%) : ";
cin>>s.final;
//now write to the file
outdata.seekp(((s.Sno)-1) * sizeof(s));
outdata.write((char*) &s, sizeof(s));
outdata.close();
cout<<"\nData has been saved";
//getch();
}