integer/float input

Jun 30, 2008 at 12:24am
I know I am overlooking something obvious, but I need to read from a binary file into integer and float variables. .read of course takes strings and I cannot get the >> operator to read only a specified amount of bytes. Any suggestion is appreciated.
Last edited on Jun 30, 2008 at 1:01am
Jun 30, 2008 at 1:40am
Is your file in binary format or human-readable text format?
Jun 30, 2008 at 11:03am
It is definitely not human-readable, it appears as a bunch of garbage characters. I t is in binary format.
Jun 30, 2008 at 3:12pm
Next question is, do you know what size each item is? In other words, is the file a list of float (single-precision) or long float (double precision)? And do you know the endianness of the file?
Jun 30, 2008 at 3:43pm
There are some of each size, but yes I do know which is which, where they are located in the file and the order in which they appear. I am not sure of the endianness, possibly middle-endian.
Jun 30, 2008 at 4:53pm
You should take a look through this thread
http://www.cplusplus.com/forum/general/2417/

For floating point numbers, you'll have to use a union to put each byte in the proper spot.

Hope this helps.
Topic archived. No new replies allowed.