title: Parsing binary files in C++
body: <p>I'm trying to read a binary format using C++
  For some reason I'm able to parse only the first variable.
  The header sequence is:
  [2 byte integer][1 byte integer][1byte integer]</p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;fstream&gt;
  
  using namespace std;
  
  struct HDR {
  unsigned short int signature;
  unsigned char version;
  unsigned char tricnt;
  } header;
  
  int main(){
      ifstream infile("1.mdl",ios::in | ios::binary);
      if(!infile){
          cout&lt;&lt;"Error\n";
          return 1;
      }
      infile.read(reinterpret_cast&lt;char *&gt;(&amp;header),sizeof(HDR));
      cout&lt;&lt;"SIG "&lt;&lt;header.signature&lt;&lt;endl;
      cout&lt;&lt;"VER "&lt;&lt;header.version&lt;&lt;endl;
  
      cout&lt;&lt;"TRI "&lt;&lt;header.tricnt&lt;&lt;endl;
      return 0;
  }
  </code></pre>
  
  <p>For some reason I'm able to parse only the signature, the rest of the structure is empty.</p>