dynamic array pointer to binary file

Posted by Yijinsei on Stack Overflow See other posts from Stack Overflow or by Yijinsei
Published on 2010-03-14T08:19:28Z Indexed on 2010/03/14 8:25 UTC
Read the original article Hit count: 358

Filed under:
|
|
|

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?

© Stack Overflow or respective owner

Related posts about binary

Related posts about c++