title: Create a streambuf from const char* WITHOUT boost?
body: <p>Same question as <a href="https://stackoverflow.com/questions/38208850/create-a-streambuf-from-const-char">Create a streambuf from const char*</a> except that <strong>I can't use boost</strong>.</p>
  <p>I have to implement an function that takes a <code>const char *</code> as input parameter, and to do so I have to call an other function that takes a <code>istream</code> as input parameter.</p>
  <p>Here is a sample of code very simplified:</p>
  <pre><code>#include &lt;iostream&gt;
  #include &lt;string&gt;
  using namespace std ;
  
  void inner_function_I_cant_change ( istream &amp; input ) // the function I must use
      {
      string s ; // dummy implementation
      input &gt;&gt; s ;
      cout &lt;&lt; s.size() &lt;&lt; &quot; : &lt;&quot; &lt;&lt; s &lt;&lt; &quot;&gt;&quot; &lt;&lt; endl ;
      }
  
  struct externbuf : streambuf // my own streambuf using a char*...
      {
      int    size ;
      bool   done ;
      char * buffer ;
  
      externbuf ( const char * buffer , int size ) :
          size(size),
          done(false),
          buffer(const_cast&lt;char*&gt;( buffer )) {} // ...that forces me to an ugly const_cast !
  
      int underflow () 
          {
          if (this-&gt;gptr() == this-&gt;egptr()) 
              {
              if (done) return std::char_traits&lt;char&gt;::eof() ;
              this-&gt;setg( buffer,buffer,buffer+size ) ;
              done = true ;
              }
          return char_traits&lt;char&gt;::to_int_type( *this-&gt;gptr()) ;
          }
      };
  
  void API_function_I_must_povide ( const char * data , int size ) // the function I must implement
      {
      externbuf buf( data,size ) ;
      istream   input( &amp;buf ) ;
      inner_function_I_cant_change( input )  ;
      }
  
  int main ()
      {
      API_function_I_must_povide( &quot;bazinga!&quot;,8 ) ;
      }
  </code></pre>
  <p>This code I works well but I had to do an ugly <code>const_cast</code> !<br />
  I tried using a <code>basic_streambuf&lt;const char, char_traits&lt;const char&gt; &gt;</code> instead of a <code>streambuf</code> but I get many errors that I didn't understand well.</p>
  <p>Is there a proper way to do it ?<br />
  (and, as I said, I can't use <em>boost</em>)</p>
  <p>Thanks !</p>