dynamic array pointer to binary file
- by Yijinsei
Hi guys,
Know this might be rather basic, but I been trying to figure out how to one after create a dynamic array such as
double* data = new double[size];
be used as a source of data to be kept in to a binary file such as
ofstream fs("data.bin",ios:binary");
fs.write(reinterpret_cast<const char *> (data),size*sizeof(double));
When I finish writing, I attempt to read the file through
double* data = new double[size];
ifstream fs("data.bin",ios:binary");
fs.read(reinterpret_cast<char*> (data),size*sizeof(double));
However I seem to encounter a run time error when reading the data. Do you guys have any advice how i should attempt to write a dynamic array using pointers passed from other methods to be stored in binary files?