我从以下代码块获取以下输出:

    //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();


这里不需要指针。

09-30 14:24