S
someone
Hi,
Here's my program:
==========================
#include <fstream>
#include <iostream>
#include <string>
#include <sstream>
#include <stdio.h>
//#include <boost/cstdint.hpp> // <-- I know this is not the group to
ask in, maybe unnecessary
using namespace std;
int main( int argc, const char* argv[] )
{
ifstream:os_type fsize;
char * memblock;
ifstream infile;
cout << "Program to read SENSOR file (for FLEX5). Build on: " <<
__DATE__ << " / " << __TIME__ << endl;
infile.open("DELETEME.res", ios::in|ios::binary);
if (infile.is_open())
{
infile.seekg (0, ios::end); // go to end of file
fsize = infile.tellg();
infile.seekg (0, ios::beg); // go to beginning
cout << "Size of file is: " << fsize << " bytes." << endl;
memblock = new char [fsize];
infile.read (memblock, fsize);
infile.close();
//cout << "the complete file content is in memory" << endl;
}
else
cout << "Unable to open file" << endl;
cout << endl; // delimiter before program outputs read data
int R1_begin;
R1_begin = static_cast<typeof R1_begin> (memblock[0]);//, 1,
'uint32',endianNess);
cout << "Value = " << R1_begin << endl;
delete[] memblock;
return 0;
}
==========================
Problem:
R1_begin is the first value read from a binary file. But it's wrong!
It should be 72 but the program prints 49 out to the screen. So I
cannot continue before I get this right. The first few bytes I'm going
to read is:
R1begin = 1 byte times sizeof 'uint32' = 4 bytes
I1_I6 = 6 bytes times sizeof 'uint32' = 6x4 = 24 bytes
TEXT = 40 ASCII characters of type 'char' = 40 bytes
R1end = 1 byte times sizeof 'uint32' = 4 bytes
Total bytes read = 4+24+40+4 = 72 bytes. That's why I must read 72
bytes from the very first byte in the binary file... And I cannot
solve this! :-(
Please help (and please provide hints for reading the next few bytes
and how I should convert from data in memory into different data
types). Later I also need to convert some bytes from memblock[ ] into
floats and doubles...
I'm stuck...
And what about big endian / little endian? I'm confused. Looking
forward to hear from you!
Here's my program:
==========================
#include <fstream>
#include <iostream>
#include <string>
#include <sstream>
#include <stdio.h>
//#include <boost/cstdint.hpp> // <-- I know this is not the group to
ask in, maybe unnecessary
using namespace std;
int main( int argc, const char* argv[] )
{
ifstream:os_type fsize;
char * memblock;
ifstream infile;
cout << "Program to read SENSOR file (for FLEX5). Build on: " <<
__DATE__ << " / " << __TIME__ << endl;
infile.open("DELETEME.res", ios::in|ios::binary);
if (infile.is_open())
{
infile.seekg (0, ios::end); // go to end of file
fsize = infile.tellg();
infile.seekg (0, ios::beg); // go to beginning
cout << "Size of file is: " << fsize << " bytes." << endl;
memblock = new char [fsize];
infile.read (memblock, fsize);
infile.close();
//cout << "the complete file content is in memory" << endl;
}
else
cout << "Unable to open file" << endl;
cout << endl; // delimiter before program outputs read data
int R1_begin;
R1_begin = static_cast<typeof R1_begin> (memblock[0]);//, 1,
'uint32',endianNess);
cout << "Value = " << R1_begin << endl;
delete[] memblock;
return 0;
}
==========================
Problem:
R1_begin is the first value read from a binary file. But it's wrong!
It should be 72 but the program prints 49 out to the screen. So I
cannot continue before I get this right. The first few bytes I'm going
to read is:
R1begin = 1 byte times sizeof 'uint32' = 4 bytes
I1_I6 = 6 bytes times sizeof 'uint32' = 6x4 = 24 bytes
TEXT = 40 ASCII characters of type 'char' = 40 bytes
R1end = 1 byte times sizeof 'uint32' = 4 bytes
Total bytes read = 4+24+40+4 = 72 bytes. That's why I must read 72
bytes from the very first byte in the binary file... And I cannot
solve this! :-(
Please help (and please provide hints for reading the next few bytes
and how I should convert from data in memory into different data
types). Later I also need to convert some bytes from memblock[ ] into
floats and doubles...
I'm stuck...
And what about big endian / little endian? I'm confused. Looking
forward to hear from you!