title: C++ Read Binary file containing numbers of type double
body: <p>I have a binary file that contains numbers of a type double.<br>
  The example input file is available here: www.bobdanani.net/download/A.0.0<br>
  I would like to read the file and print the numbers in it. 
  This is what I have done:  </p>
  
  <pre><code>char* buffer;
  int length;
  string filename = "A.0.0";
  ifs.open (filename.c_str(), ios::in | ios::binary);
  // get length of file:
  ifs.seekg (0, ios::end);
  length = ifs.tellg();
  ifs.seekg (0, ios::beg);
  // allocate memory:
  buffer = new char [length];
  // read data as a block:
  ifs.read (buffer,length);
  ifs.close();
  
  cout.write (buffer,length);
  cout &lt;&lt; buffer &lt;&lt; endl;
  
  delete[] buffer;
  </code></pre>
  
  <p>I have also tried to use a type casting to double when printing the number, but I got strange characters. What is the best way to do this? I need the data of this binary file as an input to a function for a parallel program. But this is out of the scope of this question.  </p>