title: ostream read/write functions
body: <p>I have the following function:</p>
  
  <pre><code>void IBinary::writeb( std::ostream&amp; out, double x )
  {
     out.write( (char*)&amp;(x), sizeof(double) );
  }
  </code></pre>
  
  <p>This takes the address of <code>x</code> and casts it to a pointer of type <code>char*</code>. I do not understand how/why the first argument to <code>write</code> is of type <code>char*</code>, even if I'm writing a <code>double</code> to a file. There are several overloads of the <code>writeb</code> function and all of them cast to a <code>char*</code>.</p>
  
  <p>Wouldn't that be the equivalent of:</p>
  
  <pre><code>double x = 3.14;
  char* c;
  c = (char*)&amp;(x);    // ah!
  </code></pre>
  
  <p>My guess is that this works because we are also passing the size of <code>double</code> to <code>ostream::write</code>. On my computer the size of <code>char</code> is 1 byte, but that isn't always going to be true.</p>
  
  <p>Thus, why does the first argument of <code>ostream::write</code> expect a <code>char*</code> no matter what type of variable is being written?</p>