第二次打开文件无法写入。。。
const Book mark = {"0","0","0","0","0","0"}; //empty record
const char* bookDat = "D:\\book.dat";
bool flag = true;
void adminWidget::Initial()
{
QMessageBox box;
box.setWindowTitle("Warning");
box.setIcon(QMessageBox::Warning);
box.setText("If data file exists , it will delete original data.\nContinue ?");
box.setStandardButtons(QMessageBox::Yes | QMessageBox::No);
if(box.exec() == QMessageBox::Yes)
{
ofstream bdat(bookDat,ios::out | ios::binary);
if(!bdat)
{
QMessageBox::warning(this,tr("Warning"),tr("The file does not exist!"),QMessageBox::Yes);
flag = false;
return;
}
bdat.seekp(0, ios::beg);
bdat.write((char*) & mark, sizeof(Book));
bdat.close();
}
}
void adminWidget::Append()
{
Book book;
fstream bdat(bookDat,ios::in | ios::out | ios::binary);
if(!bdat)
{
QMessageBox::warning(this,tr("Warning"),tr("The file does not exist!"),QMessageBox::Yes);
return;
}
bdat.seekg(0,ios::beg);
do
{
bdat.read((char*)&book,sizeof(Book));
}while(!endMark(book));
bdat.seekp(-long(sizeof(Book)),ios::cur);
book.number = ui->bookNum->text();
book.bookName = ui->bookName->text();
book.Author = ui->Author->text();
book.publish_company = ui->publishingCom->text();
book.quantity = ui->bookQuantity->text();
book.price = ui->price->text();
bdat.write((char*)&book,sizeof(Book));
bdat.write((char* )&mark,sizeof(Book));
bdat.close();
}
先调用Initial()初始化文件,可正常调用Append()写文件。。第二次开始就不必调用Initial(),直接调用Append()。。。出错了。。为什么?哪里有问题?望指教!
...全文
相关推荐
Centos系统下“无法打开并写入文件”问题的解决
摘要 最近在工作中发行限了一个问题,当前是root用户,去编辑/etc/ssh/sshd_config 却提示没有权限修改。报错如”/etc/ssh/sshd_config” E212: 无法打开并写入文件。 问题思考 既然提示没有权限,又是root用户,看肯定是给该文件设置了特殊的权限。检查特殊权限设置: getfacl lsattr getfacl 结果正常 root@pts/1 $ getfacl /etc/ssh/sshd_config getfacl: Removing leading '/' from absolute path names # file: etc/ss
python write无法写入文件的解决方法
今天小编就为大家分享一篇python write无法写入文件的解决方法,具有很好的参考价值,希望对大家有所帮助。一起跟随小编过来看看吧
Python打开文件,将list、numpy数组内容写入txt文件中的方法
今天小编就为大家分享一篇Python打开文件,将list、numpy数组内容写入txt文件中的方法,具有很好的参考价值,希望对大家有所帮助。一起跟随小编过来看看吧
pb操作TXT文件(打开,写入,关闭,删除等等)
pb操作TXT的一些方法的整理,希望对大家有帮助
SAMBA问题文件无法写入及多组权限设置
请教SAMBA问题文件无法写入及多组权限设置



