basic_streambuf::pubsetbuf
basic_streambuf::pubsetbuf
To set an allocation after construction.
basic_streambuf<char_type, traits> *pubsetbuf
(char_type* s, streamsize n);
The first argument is used in an another function by a filebuf derived class. See
setbuf(). The second argument is used to set the size of a dynamic allocated buffer.
Returns a pointer to basic_streambuf<char_type, traits> via
setbuf(s, n).
#include <iostream>
#include <sstream>
const int size = 100;
char temp[size] = "\0";
int main()
{
using namespace std;
stringbuf strbuf;
strbuf.pubsetbuf('\0', size);
strbuf.sputn("CodeWarrior",50);
strbuf.sgetn(temp, 50);
cout << temp;
return 0;
}
Result:
CodeWarrior