MathGroup Archive 2004

[Date Index] [Thread Index] [Author Index]

Search the Archive

Reading a binary file generated from c++ code


Hello, I have some c++ code that is generating a binary file of type
doubles.  When I use mathematica to read the file I get the wrong
data.  I have successfully been able to do this with the C++ long
type, but not float or double.

Here is the C++ code:

ofstream outfile(filename, ios::binary);
outfile.write((char*)vectorData, dimension*sizeof(double));
outfile.close();


Where vectorData is simply an array of type double and dimension is
the size of the array.

Here is the mathematica code:
ReadListBinary["c:\\test2.txt", Double]

Now if you change the types to long the correct values appear.

What gives?

Stephen


  • Prev by Date: Re: FindMinimum: foo[x_?NumericQ] vs. NumberQ
  • Next by Date: Printing digits of Pi
  • Previous by thread: Re: FindMinimum: foo[x_?NumericQ] vs. NumberQ
  • Next by thread: Re: Reading a binary file generated from c++ code