如何正确关闭我的BinaryReader类,以便我可以再次打开同一个文件?

时间:2015-10-20 15:19:41

标签: c++ .net visual-studio-2010 io

使用VC ++ 2010,.NET 3.5

我的应用程序在此行上的do..while循环的第二次迭代中崩溃

System::IO::BinaryReader^ binReader = ...

System::String^ fileName = GetFileName();
bool continue = true;
do {
    System::IO::BinaryReader^ binReader = gcnew System::IO::BinaryReader(System::IO::File::Open(fileName, System::IO::FileMode::Open));
    //
    // read file,
    // do things,
    //
    binReader.close();
    delete binReader;
} while (continue);

它编译得很好,但是在运行时,我得到了#34; ...停止工作"对话框(在第二次迭代中,我通过在循环的开头放置一个:: MessageBox()来检查)

如何正确关闭BinaryReader类,以便再次打开同一个文件?

0 个答案:

没有答案