在 DOS 上使用 DJGPP 读取二进制文件时,此代码挂起。这发生在进行 fread 调用时。如果调用被删除,则程序成功运行。相同的代码在 Visual C++ 2008 中运行良好。有没有人遇到过与 djgpp 类似的问题?我错过了一些非常简单的东西吗?
char x;
string Filename = "my.bin" ;
fp = fopen(Filename.c_str(),"rb");
if (fp == NULL)
{
cout << "File not found" << endl ;
}
if (fseek (fp, 0, SEEK_END) != 0)
{
cout <<"End of File can't be seeked";
return -1;
}
if ( (fileLength = ftell(fp)) == -1)
{
cout <<"Can't read current position of file";
return -1;
}
if (fseek (fp, 0, SEEK_SET) != 0)
{
cout <<"Beginning of File can't be seeked";
return -1;
}
if (fread(&x,sizeof(x),1,fp) != sizeof(x))
{
cout <<"file not read correctly";
return -1;
}