title: Put a binary char array in a file C++
body: <p>I'm writing a program where one server send binary messages to a client.
  I receive the binary data sent by the server, but then I can't get it into a file correctly.
  The objective is then to decrypt the file with openSSL.</p>
  <p>Here is my code:</p>
  <pre><code>int     client::_writeFile()
  {
      char    buf[bytes_received * bytes_received];
      recv(this-&gt;_socket, buf, bytes_received, 0);
      std::string const file(&quot;files/recv&quot;);
      std::ofstream f(file.c_str(), std::ios::binary);
      
      for (int i = 0; i &lt; bytes_received + 1; i++)
      {
          f.write(&amp;buf[i],sizeof(buf[i]));
      }
      f.close();
  
      system(&quot;openssl enc -d -aes-256-cbc -in files/recv -out files/decrypted.txt -pass pass:.key&quot;);
      
      return (SUCCESS);
  }
  </code></pre>
  <p>Thank you in advance for your help!</p>