C++中怎么把类对象写入文件

2025-01-06 12:45:50
推荐回答(1个)
回答1:

class t{
int a;
double b;
public:
void set(){
float c,d;
cin>>c>>d;
a=c;
b=d;
}
};
int main(){
t st;
st.set();
file *fptr;
if((fptr=fopen("writetest.dat","wb"))!=NULL)
fwrite(&st,sizeof(st),1,fptr);
fclose(fptr);
}