The RoseOutputString class is a subclass of RoseOutputStream that is an in-memory string-builder stream. It just stores everything in the write buffer and expands as needed. The flush() function has been implemented to null terminate the buffer, expanding if needed.

At any point, you can null terminate the string in place and access it with as_string() or you can generate a copy of the string with as_strobj().

If you want to empty the stream, just set the buffer position to zero with curpos(0).

RoseOutputString stream;
stream.put("Hello World\n");
stream.put("How Are You\n");

const char * stream_contents = stream.as_string();


const char * as_string();

The as_string() function null terminates the string in place and returns a pointer to the start of the buffer. This is a pointer into the live data, so it will become invalid (no longer null terminated or buffer reallocated) if you call put() again or delete the stream. Use as_strobj() to get a copy of the string.


RoseStringObject as_strobj();

The as_strobj() function returns a copy of the string. Since it is a copy, you can continue calling put() to expand the data in the stream without affecting the returned copy.