【发布时间】:2020-05-26 04:46:07
【问题描述】:
void Employee::store_data(string filename) {
fstream file;
file.open(filename,ios::app | ios::binary);
if (file) {
file.write((char*)&this,sizeof(this));
file.close();
}
else cout<<"\n Error in Opening the file!";
}
这是我尝试过的。 我想将员工类的当前对象以二进制模式存储到文件中。 但我明白了这个
error: lvalue required as unary '&' operand
file.write((char*)&this,sizeof(this));
【问题讨论】:
标签: c++ object file-handling ostream this-pointer