0

我需要读取一个文件(不是二进制模式)。我已经有一个知道文件大小的代码,我正在搜索的是如何通过=(文件大小)-8276 字节读取文件。这些已读取的字节将存储在一个变量中,我需要将其写入。

文件的大小存储在一个无符号长变量中。有谁能够帮我?

我使用 Borland C++

4

1 回答 1

0

尝试这个。我接触 Borland 已经有一段时间了,所以语法可能有点不对劲。考虑它是伪代码,但你明白了这个概念。

// assuming you've already created the file handle.
HANDLE fileHandle;

unsigned long fileSize;
unsigned long numBytesRead;
bool result;

// get the file size
fileSize = GetFileSize(theFile, NULL);

// check to see if filesize is greater than 8276 bytes.
// if so, read (fileSize - 8276)

if(fileSize >= 8276)
{
result = ReadFile(fileHandle, &objectYouAreReadingItTo, (fileSize - 8276), numBytesRead);
}
else
{
  //...handle when fileSize is less than 8276 bytes...
}
于 2012-06-26T02:20:36.357 回答