title: Writing to binary file in C++ and C#
body: <p>I have 2 applications. One in C++ (windows) open a binary file and only reads from it, i use:</p>
  
  <pre><code>fstream m_fsDataIN.open("C:\TTT", ios::in | ios::binary | ios::app);
  </code></pre>
  
  <p>and the second application (is in C#) opens the file and writes to it. I use: </p>
  
  <pre><code>byte[] b = ... //have a binary data
  System.IO.BinaryWriter bw = new System.IO.BinaryWriter(
                          System.IO.File.Open(@"C:\TTT",
                          System.IO.FileMode.Append,
                          System.IO.FileAccess.Write,
                          System.IO.FileShare.ReadWrite));
  bw.Write(b);
  bw.Flush();
  bw.Close();
  </code></pre>
  
  <p>The problem is that the 8 first bytes are written incorrectly, comparing to what appears in the <code>b</code> array.</p>
  
  <p>When I open the file in the C# application, using <code>System.IO.FileMode.Append</code> it works OK.</p>
  
  <p>I checked in the application and it writes wrong 8 bytes.</p>
  
  <p>I want to add that the first 8 bytes are 2 counters that each was created using <code>IPAddressHostToNetworkAddress</code>.</p>
  
  <p>I think that the problem is in the C++ application, in how I open the file.</p>
  
  <p>Help, 
  Thnaks</p>