🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: gnu.g++.help
Article #757

Re: ostrstream

#757
From: Brandon Wallace
Date: Fri, 01 Sep 1995 15:00
34 lines
1962 bytes
On 30 Aug 1995, Donald Hunter wrote:

=> In article <41ve2f$2hk@gabi.gabi-soft.fr> kanze@gabi-soft.fr (J. Kanze) writes:
=> 
=> > 
=> > 2. The other alternative is just to have the str function add the '\0'.
=> > This is simple: you only add it when you need it.
=> >
=> 
=> I think this behaviour would be desirable. str() returns a pointer to
=> a string and by convention these are terminated with a '\0'.  It is
=> quite dangerous for str() to return a pointer to a character buffer
                                         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
=> which is not terminated with a '\0'. 
=> 
=> Donald.

You answered your own question.  str() returns a pointer to a character
buffer, *not* a pointer to a string!
If you are using strstream to fill in a CHARACTER BUFFER, then you
certainly don't want str() mucking the works by appending a '\0'.

In fact, in my manual, the description reads:

       strstream - stream class for "I/O" using character arrays

It says nothing about nul-terminated strings.
I think it is perfectly reasonable to make you go:  ostr << ends;
before calling str();
--
                      Brandon Wallace
            Nicholas | Applegate Capital Management
mailto:bman@criterion.com  http://www.criterion.com/home-pages/brandon
          "I live life face down in the fast lane."
Technical Details
Message-ID: <Pine.SUN.3.91.950901095215.17250F-100000@achilles>
Path: arc1-ca.pugleaf.net!nacm.com!achilles!brandon
References: <9508281944.AA10055@vital> <DE1xy6.EyI@info.physics.utoronto.ca> <41ve2f$2hk@gabi.gabi-soft.fr> <w5rb23ielw.fsf@pegasus.memex>

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!nacm.com!achilles!brandon
From: Brandon Wallace <brandon@achilles>
Newsgroups: gnu.g++.help,comp.lang.c++
Subject: Re: ostrstream
Date: Fri, 1 Sep 1995 10:00:53 -0500
Organization: Nicholas|Applegate Capital Management, San Diego, CA
Message-ID: <Pine.SUN.3.91.950901095215.17250F-100000@achilles>
References: <9508281944.AA10055@vital> <DE1xy6.EyI@info.physics.utoronto.ca>
 <41ve2f$2hk@gabi.gabi-soft.fr> <w5rb23ielw.fsf@pegasus.memex>
NNTP-Posting-Host: achilles.criterion.com
Mime-Version: 1.0
Content-Type: TEXT/PLAIN; charset=US-ASCII
In-Reply-To: <w5rb23ielw.fsf@pegasus.memex>