To return the character array stored in the buffer.
char* str();
The function str() freezes the buffer and appends a null character then returns the beginning pointer for the input sequence. The user is responsible for destruction of any dynamically allocated buffer.
#include <iostream> #include <strstream> const int size = 100; char buf[size]; char arr[size] = "CodeWarrior - Software at Work"; int main() { ostrstream ostr(buf, size); ostr << arr; // associate buffer strstreambuf *strbuf(ostr.rdbuf()); // do some manipulations strbuf->pubseekoff(10,ios::beg); strbuf->sputc('\0'); strbuf->pubseekoff(0, ios::beg); cout << "The original array was\n" << arr << "\n\n"; cout << "The strstreambuf array is\n" << strbuf->str() << "\n\n"; cout << "The ostrstream array is now\n" << buf; return 0; }