The ostrstream class supports output streams that have character arrays as a destination. You can allocate a character array prior to construction, or the constructor can internally allocate an expandable array. All the ostream operators and functions can then be used to fill the array.
You must be aware that there is a put pointer working behind the scenes in the attached strstreambuf class. This pointer advances as you insert fields into the stream's array. The only way you can make it go backwards is to use the ostream::seekp function. If the put pointer reaches the end of user-allocated memory (and sets the ios::eof flag), then you must call clear before seekp.
#include <strstrea.h>
strstreambuf, streambuf, strstream, istrstream