#include <bits/stdc++.h>
using namespace std;
class student
{
string name;
string reg;
public:
void getdata()
{
getline(cin,name);
getline(cin,reg);
}
void printdata()
{
cout<<name<<"\t"<<reg<<endl;
}
};
int main()
{
ifstream fin;
ofstream fout;
student obj;
fout.open("google.txt",ios::out|ios::binary);
obj.getdata();
fout.write((char*)&obj,sizeof(obj));
fout.close();
student obj2;
fin.open("google.txt",ios::in|ios::binary);
fin.read((char*)&obj2,sizeof(obj2));
obj2.printdata();
fin.close();
return 0;
}
I am trying a basic read and write operation of file handling of objects.
But after executing the above code I am successfully able to write and read but I get an error message *** Error in ./io: free(): invalid size: 0x00007ffea93f64b0 ***Aborted (core dumped)
Input:
Fire Blade
, 17HFi394
Output:
Fire Blade , 17HFi394
and an error message : *** Error in ./io: free(): invalid size: 0x00007ffea93f64b0 ***Aborted (core dumped)
Can anyone explain this error and what should I do to overcome this problem.