title: read binary data from `stringstream`
body: <p>for more background, <a href="https://stackoverflow.com/questions/14142649/creating-an-iostream-object-in-c/14142686">see here</a></p>
  
  <p>I am using a <code>stringstream</code> to read through binary data.  As of now, I am simply writing a dummy program to get comfortable with the class.  Here's my program:</p>
  
  <pre><code>#include &lt;sstream&gt;
  #include &lt;iostream&gt;
  #include &lt;iomanip&gt;
  #include &lt;cstdio&gt;
  
  using namespace std;
  
  string bytes2hex(char* bytes, int n){
      stringstream out;
      for (int i = 0;i &lt; n;i++){
          out &lt;&lt; setfill ('0') &lt;&lt; setw(2) &lt;&lt; hex &lt;&lt; (int) bytes[i] &lt;&lt; " ";
      }
  
      string st = out.str();
      for(short k = 0; k &lt; st.length(); k++)
      {
          st[k] = toupper(st[k]);
      }
  
      return st;
  }
  
  int main(){
      stringstream ss;
  
      ss &lt;&lt; "hello the\0re my\0\0\0 friend";
  
      while (ss.peek() != EOF){
          char buf [2];
          ss.get(buf, 3);
          cout &lt;&lt; buf &lt;&lt; "\t==&gt;\t" &lt;&lt; bytes2hex(buf, 2) &lt;&lt; endl;
      }
  }
  </code></pre>
  
  <p>Output:</p>
  
  <pre><code>he  ==&gt; 68 65 
  ll  ==&gt; 6C 6C 
  o   ==&gt; 6F 20 
  th  ==&gt; 74 68 
  e   ==&gt; 65 00 
      ==&gt; 00 00 
  </code></pre>
  
  <p>I have 2 questions on this:</p>
  
  <ol>
  <li>Why is it that, when I execute <code>ss.get()</code>, I have to input 3, rather than 2, to read the stream 2 characters at a time?</li>
  <li>Why does it terminate on the first null character, and how do I prevent that from happening?</li>
  </ol>