I'm working with a binary file that I need to grab its useful contents from. The structure is:
1 Answer
Based on a quick look at the file, you don't have an "unknown amt of nulls" anywhere. The format appears to be:
N Bytes: number of animals, integer as text delimited by '\n'
24 Bytes per animal:
16 Bytes: name of animal padded with 0
4 Bytes: some 32 bit number (little endian)
4 Bytes: another 32 bit number (little endian)
You shouldn't be reading this as a text file, but instead as a raw binary file. There's absolutely no need for a stringstream, you can simply parse the number of animals by reading in one byte at a time and adding to the previous value * 10 until you reach '\n'.
stringstreamis very well suited to deal with binary files.stringstream(although I don't see any real use for it here); the problem is that he's trying to use formatted IO on binary data. There's no way that will work, since the formatting is all text oriented.