MathGroup Archive 2004

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

Search the Archive

Reading a binary file generated from c++ code

  • To: mathgroup at smc.vnet.net
  • Subject: [mg46706] Reading a binary file generated from c++ code
  • From: rsaghost at hotmail.com (Stephen)
  • Date: Tue, 2 Mar 2004 00:14:33 -0500 (EST)
  • Sender: owner-wri-mathgroup at wolfram.com

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