static std::vector<char> ReadAllBytes(char const* filename)
{
ifstream ifs(filename, ios::binary|ios::ate);
ifstream:

os_type pos = ifs.tellg();
std::vector<char> result(pos);
ifs.seekg(0, ios::beg);
ifs.read(&result[0], pos);
return result;
}
void readFromFile()
{
vector<char> byteArrayfromFile = ReadAllBytes("test.bin");
qDebug()<<byteArrayfromFile.size();
union
{
char b[8];
double d;
};
for (int i=0;i<byteArrayfromFile.size()-7;i++)
{
b[7] = byteArrayfromFile.at(i+0);// 0x3F;
b[6] = byteArrayfromFile.at(i+1);//0xD1;
b[5] = byteArrayfromFile.at(i+2);//0x9B;
b[4] = byteArrayfromFile.at(i+3);//0x94;
b[3] = byteArrayfromFile.at(i+4);//0xC0;
b[2] = byteArrayfromFile.at(i+5);//0x00;
b[1] = byteArrayfromFile.at(i+6);//0x00;
b[0] = byteArrayfromFile.at(i+7);//0x00;
qDebug()<<"double"<<d;
}
}
Bookmarks