title: How to read and write binary SHA1 digest from std::fstream
body: <p>I need to read and write a hex encoded SHA1 value in the file.
  If I wanted to write <code>C30A</code> then I need to convert <code>C30A</code> into character array whose length is equal to half the length of the hashvalue since a byte can hold two hex characters;
  for <code>C30A</code>,</p>
  <pre class="lang-cpp prettyprint-override"><code>    char array[2];
      array[0] = 11000011=195;
      array[1] = 00001010=10;//which is an ascii for '\n'
  </code></pre>
  <p>If I wanted to write this <code>char array</code>
  I have done: <code>filestream&lt;&lt;array;</code></p>
  <p>Now when I want to read it from file how should I read it?</p>
  <p>I tried doing</p>
  <pre class="lang-cpp prettyprint-override"><code>    std::string str;
      filestream&gt;&gt;str;
  </code></pre>
  <p>But it stops whenever it encounters whitespace characters like <code>'\0'</code>,<code>'\r'</code>,<code>'\n'</code> etc.
  And It always ends up reading only a portion of the hash, since there will be those character for sure.</p>
  <p>What way should I go to read and write in this case?</p>