I am trying to read a binary file and extract the data.
In the first part of the file there is an XML header with meta data. I haven't gotten to the part where I examine yet how to get past this and am working on the data itself for now.
I removed the header and am now left with the data itself and looking at it with a hex editor it appears to be 'long' followed by '0x00' then 'float'
I have tried various ways to read this in C++ and output the information but I just don't know what I am doing apparently.
This is my latest attempt. I was able to read it as character, but I don't know how to go beyond this.
So I'm looking for help, examples, places to go to read more about how to do this.
A little later::
After looking at this again, maybe I should be using a buffer with a pointer and to read 'float' at the reference. I think I'll give it a shot.
the binary mode read gives just raw files and there is no formatting of the characters. the way you are doing it, it wont give correct results. secondly you should know the boundries of the stream to read the binary file. lets take an example from your stream only:
C'$M^@E<80>]¾C&ýR^@E<82>@ßC
now lets say you are getting this and which is in this form:
bytes 0-3 data1(long)
bytes 4-7 data2(float)
bytes 8-15 data3(byte array or character array)
now how will you read it:
char buff[128];
long data1;
float data2;
char data3[16];
1 2 3 4 5 6 7 8
file.read(buff, 4); //this will read data1 in array, you need to make it to long
data1 = atol(buff);
file.read(buff, 4); //this will read data2
data2 = atof(buff); //convert to float
file.read(buff, 8);
strcpy(data3, buff); //created data3
hope you are getting what i mean.. try on the same lines...