0

我有一个有两部分的大文件。第一个是标题,它使用标准字符并以[END]. 第二部分是二进制的,看起来像:NUL DLE NUL DC1 NUL. 我正在尝试使用 ifstream 阅读本文档。我的代码是:

std::string filename = "file.txt";
std::ifstream originalFile;
originalFile.open(filename,std::ios::binary);

std::streampos fsize = 0;
fsize = originalFile.tellg();
originalFile.open(0,std::ios::end);
fsize = originalFile.tellg() - fsize;

char * buffer = new char [int(fsize)];
originalFile.seekg(0,std::ios::beg);
originalFile.reade(buffer,fsize);

std::cout << fsize << std::endl;
std::cout << buffer << std::endl;

当我运行它时,程序会输出我文件的整个标题,然后结束。它不访问或打印任何二进制数据。这是要使用的正确命令吗?如果没有,还有什么我可以尝试的吗?

4

1 回答 1

3

Your dump of the file data (which presumably;y really looks like std::cout << buffer << std::endl;) is stopping when it hits the NUL character which it considers to be the end of a C-style string.

于 2013-10-29T16:04:39.990 回答