This is the mail archive of the
mailing list for the libstdc++ project.
static memory ostringstream use?
- From: bob at proulx dot com (Bob Proulx)
- To: libstdc++ at gcc dot gnu dot org
- Date: Sun, 10 Dec 2006 15:50:50 -0700
- Subject: static memory ostringstream use?
In old C++ I used to do things like this following to use C++ strings
to print to C char arrays. This is a fancy snprintf().
ostrstream(buf,sizeof buf) << "hello" << ends;
This result is the same as:
In this small example this is easier to use snprintf(). But in the
real case I am trying to stream objects that only exposed
operator<<() and had no other access method available. Another
requirement is to avoid using any dynamic memory. The above works
directly on the supplied character buffer.
I have read much and tried many things but so far failed to deduce
a solution using a modern compiler. Is there a way to use streams
into a static buffer without using dynamic memory? I am at a loss to
find a way to do this using the new standard library.
 I found this one particular useful. Thanks for that.