MathGroup Archive 2004

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

Search the Archive

Re: Reading a binary file generated from c++ code

  • To: mathgroup at smc.vnet.net
  • Subject: [mg46714] Re: Reading a binary file generated from c++ code
  • From: Jens-Peer Kuska <kuska at informatik.uni-leipzig.de>
  • Date: Tue, 2 Mar 2004 19:10:12 -0500 (EST)
  • Organization: Universitaet Leipzig
  • References: <c2161l$8h6$1@smc.vnet.net>
  • Reply-to: kuska at informatik.uni-leipzig.de
  • Sender: owner-wri-mathgroup at wolfram.com

Hi,

have the CPU's that generate the file and the CPU that
read the file the same endianess ??

Regards
  Jens

Stephen wrote:
> 
> 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: To create {{},{},....{}} beyond $MaxRecursionLimit
  • Next by Date: Re: Printing digits of Pi
  • Previous by thread: Reading a binary file generated from c++ code
  • Next by thread: Printing digits of Pi