Skip to content

Instantly share code, notes, and snippets.

@lakinwecker
Created February 19, 2019 19:34
Show Gist options
  • Save lakinwecker/0dceee650d72fd4501c3418b2ceb2de3 to your computer and use it in GitHub Desktop.
Save lakinwecker/0dceee650d72fd4501c3418b2ceb2de3 to your computer and use it in GitHub Desktop.
#include <iostream>
#include <fstream>
using namespace std;
const int size = 65536;
void store();
double* load();
int main() {
store();
double numbers[size];
for (int i = 0; i < size; i++) {
numbers[i] = i * 123456.789 + 2345.4321;
}
double* test = load();
for (int i = 0; i < 10; i++) {
if (test[i] != numbers[i]) {
cout << i << endl;
cout << test[i] << endl;
cout << numbers[i] << endl;
}
}
return 0;
}
void store() {
ofstream file;
file.open("doubles.ff", ios::out | ios::binary);
double numbers[size];
for (int i = 0; i < size; i++) {
numbers[i] = i * 123456.789 + 2345.4321;
}
file.write(reinterpret_cast<char *>(numbers), sizeof(double) * size);
file.close();
}
double* load() {
ifstream file;
file.open("doubles.ff", ios::in | ios::binary);
double *numbers = new double[size];
file.read(reinterpret_cast<char *>(numbers), sizeof(double) * size);
return numbers;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment