When I input data into a text file using a class object, the text file shows some weird text instead of the data I entered. I entered "Flash" and 100 but the text file shows some weird text.link to snap of text file . Any help?
#include<iostream>
#include<fstream>
using namespace std;
class Details
{
string name;
int roll;
public:
void get();
};
void Details::get()
{
cout<<"Enter name : ";
cin>>name;
cout<<"Enter Roll No. : ";
cin>>roll;
}
int main()
{
Details obj;
ofstream fout;
fout.open("newdetails.txt",ios::app);
obj.get();
fout.write((char *)&obj,sizeof(obj));
fout.close();
return 0;
}