title: Writing unsigned chars to a binary file using write()
body: <p>I was making a program that read binary files. So, I read the individual bytes into unsigned chars (actually reading the data as chars and casting them to unsigned chars for each character). Now I have to write back the unsigned chars to the binary file.</p>
  
  <p>The problem is that now I am forced to write individual bytes after casting them to chars (because write() for binary files expects char* buffer). So, now i have to do the following:</p>
  
  <pre><code>for(int x=0; x&lt;data_size; x++)
  {
      ch=(char)data[x];
      outfile.write(&amp;ch,1);
  }
  </code></pre>
  
  <p>Is there any way to get around this thing so that the amount of I/O operations are reduced in case of reading and writing?</p>