title: read double type data from binary file
body: <p>I want to read  <code>double</code> values from a <code>binary</code> file and store them in a vector. My values have the following form: 73.6634,   73.3295,   72.6764 and so on. I have this code that read and store data in memory. It works perfectly with <code>char</code> types since the <code>read</code> function has as input a <code>char</code> type (<code>istream&amp; read (char* s, streamsize n)</code>). When I try to convert <code>char</code> type to <code>double</code> I get obviously integer values as 74, 73, 73 and so on. Is there any function which allows me to read directly double values or any other way of doing that?</p>
  
  <p>If I change <code>char * memblock</code> to <code>double * memblock</code> and <code>memblock = new char[]</code> to <code>memblock = new double[]</code> , I get errors when compiling because again <code>read</code> function can only have <code>char</code> type input variable...</p>
  
  <p>Thanks, I will appreciate your help :)</p>
  
  <pre><code>// reading an entire binary file
  #include &lt;iostream&gt;
  #include &lt;fstream&gt;
  using namespace std;
  
  int main () {
  streampos size;
  char * memblock;
  
  int i=0;
  
  ifstream file ("example.bin", ios::in|ios::binary|ios::ate);
  if (file.is_open())
  {
      size = file.tellg();
  
      cout &lt;&lt; "size=" &lt;&lt; size &lt;&lt; "\n"; 
  
      memblock = new char [size];
      file.seekg (0, ios::beg);
      file.read (memblock, size);
      file.close();
  
      cout &lt;&lt; "the entire file content is in memory \n";
  
      for(i=0; i&lt;=10; i++)
      {
      double value = memblock [i];
      cout &lt;&lt; "value ("&lt;&lt;i&lt;&lt;")=" &lt;&lt; value &lt;&lt; "\n";
      }
  
  };
  
      delete[] memblock;
  }
  else cout &lt;&lt; "Unable to open file";
  return 0;
  }
  </code></pre>