0

I'm working with a binary file that I need to grab its useful contents from. The structure is:

5
  • 4
    Doesn't feel like stringstream is very well suited to deal with binary files. Commented Sep 6, 2013 at 14:50
  • Not in the slightest, in fact. Commented Sep 6, 2013 at 14:51
  • The problem isn't 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. Commented Sep 6, 2013 at 14:53
  • 1
    It's not clear what the actual input looks like. What's binary, and what is text? And if most of the file is binary, null is 0, which is a valid binary value. Commented Sep 6, 2013 at 14:55
  • @JamesKanze agreed. without a much better definition of the input file format this is somewhat nebulous in the first place. Commented Sep 6, 2013 at 15:01

1 Answer 1

2

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'.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.