char* tmp = new char[sizeof(float)];
float val = 0;
memcpy(tmp, val, sizeof(float));
val = *reinterpret_cast
This should give you some idea on how to handle binary file read. The following is the complete example, might not suit your situation though.
#include
#include
#include
#include
using namespace std;
#define interval 400
class Data {
public:
float** data;
Data (const string& file);
};
Data::Data (const string& dataFile) {
ifstream file (dataFile.c_str (),ios_base::in|ios_base::binary);
string line;
int file_length = 0;
file.seekg(0,ios::end);
file_length = file.tellg();
file_length -= 19;
file.seekg(0,ios::beg);
this->data = new float* [file_length/4];
for (int i =0 ; i< file_length/4 ; i++)
{
this->data[i] = new float [3];
}
// Read Header File, Basiclly Ignore It.
char* header = new char[19];
file.read(header,19);
int t = 0;
char* acc = new char[12*interval];
// Read Actual Data;
while (!file.eof())
{
file.read(acc,12*interval);
int read_length = file.gcount()/12;
for (int k = 0 ; k < read_length ; k ++ )
{
for(int j=0;j<3;j++)
{
this->data[t+k][j] = (*reinterpret_cast(acc+12*k+4*j));
}
}
t += read_length;
}
}
1 comment:
Thanks for the informative Content. I learned a lot here. Keep sharing more like this.
Salesforce Schema Builder
Salesforce Schema
Post a Comment