This is the mail archive of the libstdc++@gcc.gnu.org mailing list for the libstdc++ project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

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().

  #include <strstream.h>
  char buf[1024];
  ostrstream(buf,sizeof buf) << "hello" << ends;

This result is the same as:

  snprintf(buf,sizeof buf,"%s","hello");

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[1] 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.

Thanks
Bob

[1] I found this one particular useful.  Thanks for that.
    http://gcc.gnu.org/onlinedocs/libstdc++/17_intro/porting-howto.html


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]