The basic_stringbuf has two constructors to create a string buffer for characters for input/output.
explicit basic_stringbuf(ios_base::openmode which = ios_base::in | ios_base:out);
explicit basic_stringbuf(const basic_string <char_type> &str, ios_base::openmode which = ios_base::in | ios_base:out);
The basic_stringbuf constructor is used to create an object usually as an intermediate storage object for input and output. The overloaded constructor is used to determine the input or output attributes of the basic_string object when it is created.
No array object is allocated for the first basic_stringbuf constructor.
#include <iostream> #include <sstream> const int size = 100; int main() { using namespace std; stringbuf strbuf; strbuf.pubsetbuf('\0', size); strbuf.sputn("ABCDE",50); char ch; // look ahead at the next character ch =strbuf.snextc(); cout << ch; // get pointer was not returned after peeking ch = strbuf.snextc(); cout << ch; return 0; }
Result:
BC