首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > C++ >

ifstream close出错解决方案

2012-03-18 
ifstream close出错为什么这样写,会出现错误?????????ifstream file1file1.open(D:\\60x55.BMP, ios_ba

ifstream close出错
为什么这样写,会出现错误?????????  
  ifstream file1;
file1.open("D:\\60x55.BMP", ios_base::binary | ios_base::in);
if (!file1)
{
  cout<<"error";
}

file1.seekg( 0, ios::end );
fstream::pos_type flen = file1.tellg();
file1.seekg( 0, ios::beg );

char *buf = new char(flen);
file1.read(buf, flen);
 file1.close();

编译连接没问题, 但运行的时候, 会出现一个对话框,This may be due to a corruption of the heap, and indicates a bug in filectrl_test.exe or any of the DLLs it has loaded.

如果将char *buf = new char(flen);
file1.read(buf, flen);
去掉的话, 就没事,能运行。

[解决办法]
char *buf = new char[flen];

热点排行