🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

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

Re: ostrstream

#756
From: Brandon Wallace
Date: Thu, 31 Aug 1995 19:14
37 lines
1700 bytes
On 28 Aug 1995, Albert Golembiowski wrote:

=> I don't see much use for a char string picking up
=> tail-end "star dust".
=> --------------------- snip -------------------------
=> #include <strstream.h>
=> template <class Type> 
=> Str& operator <  (Str& Out, Vect<Type>& V)  // insert
=> {//__~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
=>   ostrstream buf;
=>   V.print(buf,"","","");  // put out vector values
=>   buf << '\0';            // why is this necessary?
=>   char *pb = buf.str();
=>   Out = Str(pb);
=>   delete pb;
=>   return Out;
=> }
=> --------------------- snip -------------------------

Well, here is one example where you don't want the '\0' appended onto the end:

---- snip ----
voir example (void)
{
  static char buf[100];
  ostrstream ostr(buf, 100);

  for (int i = 0; i < 100; i++) ostr << 'a';

  char *str = ostr.str();  // Certainly don't want to append a '\0', since buf[] already has 100 chars in it!
}
--- snip ---

                      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.950831140749.16915C-100000@achilles>
Path: arc1-ca.pugleaf.net!nacm.com!achilles!brandon
References: <9508281944.AA10055@vital>

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: Thu, 31 Aug 1995 14:14:13 -0500
Organization: Nicholas|Applegate Capital Management, San Diego, CA
Message-ID: <Pine.SUN.3.91.950831140749.16915C-100000@achilles>
References: <9508281944.AA10055@vital>
NNTP-Posting-Host: achilles.criterion.com
Mime-Version: 1.0
Content-Type: TEXT/PLAIN; charset=US-ASCII
In-Reply-To: <9508281944.AA10055@vital>