title: How to convert binary files context into int/long value in C++
body: <p>I am storing a value in a binary file with fstream. The value is unsigned short type.</p>
  
  <pre><code>unsigned shord value=1750; //2 byte variable
  file.write((char*)&amp;value,sizeof(value));
  </code></pre>
  
  <p>My problem is that I want to read this binary file in another function, but it gives me some weird symbols (Obviously because it is binary).<br>
  Is there any way to get those two bytes and convert them to my old value (1750) ?</p>
  
  <p>Here's what I have tried:</p>
  
  <pre><code>cout &lt;&lt;(unsigned short)(unsigned char)(s2[8]);//s2 variable where the whole body is stored
  cout &lt;&lt;(unsigned short)(char*)(s2[8]);
  </code></pre>
  
  <p>I have tried other things, too, but they were just chickenscratch and aren't worth including here.</p>