title: C++ Better Practice to Use of Streams and Buffers
body: <p>I know a way to read from a stream and use it like below:</p>
  
  <pre><code>strstream s; // It can be another standard stream type
  // ...
  while (!s.eof())
  {
    char buf[MAX];
    s.read(buf, sizeof (buf));
    int count = s.gcount();
  
    THIRD_PARTY_FUNCTION(buf, count);
    // ...
  }
  </code></pre>
  
  <p>but this code has an abusing point, It first copies data from the stream to <code>buf</code> and then passes <code>buf</code> to <code>THIRD_PARTY_FUNCTION</code>.</p>
  
  <p>Is there any way to reform the code to something like below(I mean below code avoids an extra copy) ?</p>
  
  <pre><code>strstream s; // It can be another standard stream type
  // ...
  while (!s.eof())
  {
  
    char *buf = A_POINTER_TO_DATA_OF_STREAM(s);
    int count = AVAIABLE_DATA_SIZE_OF_STREAM(s);
    // Maybe it needs s.seekg(...) here
  
    THIRD_PARTY_FUNCTION(buf, count);
    // ...
  }
  </code></pre>