title: Extracting bytes from byte stream
body: <p>I receive a binary file via POST in a C++ CGI script and I'm using the <a href="http://www.gnu.org/software/cgicc/" rel="nofollow">Cgicc</a> library to get its contents like so:</p>
  
  <pre><code>std::ofstream myfile;
  myfile.open ("file.out", std::ios::in | std::ios::binary);
  try
  {
      cgicc::Cgicc cgi;
      cgicc::const_file_iterator file = cgi.getFile("bitmap");
      if(file != cgi.getFiles().end())
      {
          file-&gt;writeToStream(myfile);
      }
  }
  
  catch(std::exception &amp;exception)
  {
      std::cout &lt;&lt; exception.what();
  }
  </code></pre>
  
  <p>The result is a binary file containing the bytes.</p>
  
  <p>Now, because each byte should represent one pixel of an 8 bit bitmap file, I want to construct the entire bitmap file. In order to achieve this, I think I can use the <a href="http://easybmp.sourceforge.net/" rel="nofollow">easyBMP</a> library, but since I need to create the image pixel by pixel, I need to somehow iterate over the received bytes. Does anyone know how this can be achieved? Can I get an iterator somehow to an std::ostream / std::ostrstream / std::ostringstream?</p>
  
  <pre><code>std::ostringstream stream;
  file-&gt;writeToStream(stream);
  //foreach byte in stream do { ... }
  </code></pre>