user2761933
user2761933

Reputation: 179

Why isn't my read statement recording binary data

I have a large document that has two pieces. The first is a header, which uses standard characters and ends with [END]. The second part is in binary, and looks something like: NUL DLE NUL DC1 NUL. I am attempting to read in this document using an ifstream. My code is:

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;

When I run it, The program outputs the entire header of my file, and then ends. It does not access or print any of the binary data. Is this the right command to be using? If not, is there something else I can try?

Upvotes: 0

Views: 64

Answers (1)

Michael Burr
Michael Burr

Reputation: 340436

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.

Upvotes: 3

Related Questions