我从以下代码块得到以下输出:
//create file for writing
cout << "'" << filename.c_str() << "'" << endl;
string outfile = filename.append(".bin");
cout << "'" << outfile.c_str() << "'" << endl;
fstream *binfile;
binfile->open (outfile.c_str(), ios::out | ios::binary);
打印:
'myfile.tmp'
'myfile.tmp.bin'
terminate called after throwing an instance of 'std::ios_base::failure'
what(): basic_ios::clear
该错误是什么意思,我该如何解决?
谢谢
最佳答案
取而代之的是:
fstream *binfile;
你应该这样做:
fstream binfile("filename", fstream::in | fstream::out | fstream::binary);
然后调用:
binfile << "write here to file";
binfile.close();
这里不需要指针。
关于c++ - 打开二进制文件写入 : terminate called after throwing an instance of 'std::ios_base::failure' 时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7420570/