Using different objects for input and output the above code is not working. Pls give suggestion ASAP.
#include<iostream>
#include<fstream>
#include<iomanip>
using namespace std;
class sample
{
int num;
char name[20];
public:
void read()
{
cout<<"\n enter name";
gets(name);
cout<<"enter the number";
cin>>num;
}
void write()
{
cout<<"\n The name is"<<name<<endl;
cout<<"\n The number is"<<num<<endl;
}
};
int main()
{
sample s1,s2;
fstream file;
file.open("d:/Arindam/samplearindam.txt",ios::in);
cout<<"Enter the details"<<endl;
s1.read();
file.write((char *)&s1,sizeof(s1));
file.close();
cout<<"\n\n\nOUTPUT";
file.open("d:/Arindam/samplearindam.txt",ios::out);
file.seekg(0);
file.read((char *)&s2,sizeof(s2));
s2.write();
file.close();
return 0;
}