void modifyData()
{
int Id;
char nm[25];
float pay;
fstream modData("Depart ment1.txt",ios: :out || ios::in || ios::binary);
if(!modData)
{
cerr<<"file could not be opened"<<"\n";
}
else
{
cout<<" Enter the ID of department you want to modify :"<<"\n";
cin>>Id;
cout<<"Enter Name of Department:";
cin>>nm;
cout<<"\n";
cout<<"Enter Salary of the Department's Employee :";
cin>>pay;
cout<<"\n";
Department d;
modData.seekg(( Id-1)*sizeof(Depar tment));
modData.read((c har*)(&d),sizeo f(Department));
d.setPayrate(pa y);
d.setName(nm);
d.setId(Id);
modData.seekp(( Id-1)*sizeof(Depar tment));
modData.write(( char*)(&d),size of(Department)) ;
}
}
this is the code to modify data in file but its not working well can any1 help me? please
{
int Id;
char nm[25];
float pay;
fstream modData("Depart ment1.txt",ios: :out || ios::in || ios::binary);
if(!modData)
{
cerr<<"file could not be opened"<<"\n";
}
else
{
cout<<" Enter the ID of department you want to modify :"<<"\n";
cin>>Id;
cout<<"Enter Name of Department:";
cin>>nm;
cout<<"\n";
cout<<"Enter Salary of the Department's Employee :";
cin>>pay;
cout<<"\n";
Department d;
modData.seekg(( Id-1)*sizeof(Depar tment));
modData.read((c har*)(&d),sizeo f(Department));
d.setPayrate(pa y);
d.setName(nm);
d.setId(Id);
modData.seekp(( Id-1)*sizeof(Depar tment));
modData.write(( char*)(&d),size of(Department)) ;
}
}
this is the code to modify data in file but its not working well can any1 help me? please
Comment