我正在尝试在“CustomerDetails”文件中读取我之前编写的对象(现在文件中只有一个对象)。我的程序总是在被计算后突然终止read first object
。
我在这里做错了什么?
ifstream file;
try
{
file.open("CustomerDetails.dat",fstream::in|fstream::binary);
if(file.is_open())
{
while(1)
{
cout<<"Current Position\n"<<file.tellg()<<endl;
file.read((char*)this,sizeof(*this));
if(file.eof()) break;
cout<<"read first object\n";
if(!(this->accountNo).compare(accountNumber)&& this->isDeleted==false)
{
cout<<"Account Found!!\n Current Balance="<<this->balanceAmount<<endl;
}
cout<<"End of loop loop\n";
}
}
else
{
cout<<"Error opening file.\n";
}
file.close();
}
catch(...)
{
cout<<"Exception Caught\n";
}