#include <iostream>
#include <fstream>
union dbl {
char mem[8];
double d;
};
int main()
{
double d[] = {1.0, 2.1, 3.2, 4.3};
std::ofstream fout("dataset.dat", std::ios::binary);
for (double* dp = d; dp != &d[sizeof(d) / sizeof(d[0])]; dp++)
fout.write(reinterpret_cast<char*>(dp), static_cast<std::streamsize>(sizeof(double)));
fout.close();
std::ifstream fin("dataset.dat", std::ios::binary);
std::istreambuf_iterator<char> buf(fin), eof;
for (; buf != eof;) {
dbl c;
c.mem[0] = *buf++;
c.mem[1] = *buf++;
c.mem[2] = *buf++;
c.mem[3] = *buf++;
c.mem[4] = *buf++;
c.mem[5] = *buf++;
c.mem[6] = *buf++;
c.mem[7] = *buf++;
std::cout << c.d << std::endl;
}
}
I2luY2x1ZGUgPGlvc3RyZWFtPgojaW5jbHVkZSA8ZnN0cmVhbT4KCnVuaW9uIGRibCB7CiAgY2hhciBtZW1bOF07CiAgZG91YmxlIGQ7Cn07CgppbnQgbWFpbigpCnsKICBkb3VibGUgZFtdID0gezEuMCwgMi4xLCAzLjIsIDQuM307CiAgCiAgc3RkOjpvZnN0cmVhbSBmb3V0KCJkYXRhc2V0LmRhdCIsIHN0ZDo6aW9zOjpiaW5hcnkpOwogIGZvciAoZG91YmxlKiBkcCA9IGQ7IGRwICE9ICZkW3NpemVvZihkKSAvIHNpemVvZihkWzBdKV07IGRwKyspCiAgICBmb3V0LndyaXRlKHJlaW50ZXJwcmV0X2Nhc3Q8Y2hhcio+KGRwKSwgc3RhdGljX2Nhc3Q8c3RkOjpzdHJlYW1zaXplPihzaXplb2YoZG91YmxlKSkpOwogIGZvdXQuY2xvc2UoKTsKICAKICBzdGQ6Omlmc3RyZWFtIGZpbigiZGF0YXNldC5kYXQiLCBzdGQ6Omlvczo6YmluYXJ5KTsKICBzdGQ6OmlzdHJlYW1idWZfaXRlcmF0b3I8Y2hhcj4gYnVmKGZpbiksIGVvZjsKICAKICBmb3IgKDsgYnVmICE9IGVvZjspIHsKICAgIGRibCBjOwogICAgY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