🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

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

initialization of ostrstream

#836
From: joost witteveen
Date: Mon, 27 Nov 1995 21:37
34 lines
1359 bytes
If I construct a ostrstream, with
  ostrstream os (s,sizeof(s))
do I have to clean ALL of s before I use it?
I'm getting strange results (i.e. I have to init ALL of s to 0)
with g++ 2.7.1, and 2.3.3.

So, my question is: is this a bug in g++, or am I missing something
about the string streams?


The following programme has this what I think is strange behaviour,
as it outputs in the last line not only the "hello, world", but
part of the old h's string s was inititalized to,  concatenated to it.

Thanks for any suggestions.


#include <iostream.h>
#include <strstream.h>
int main(int,char **){
  int i;
  char s[]="\000hhhhhhhhhhhhhhhhhhhhhhhhhhhh";
  cout<<"initial s:"<<s<<endl; //an empty string here.

  ostrstream os(s,sizeof(s));
  os<<"hello, world";
  cout<<s<<endl;          //outputs: hello, worldhhhhhhhhhhhhhhhhh
}

-- 

joost witteveen
            joost@rulcmc.leidenuniv.nl
          joostje@dds.hacktic.nl
Technical Details
Message-ID: <199511272135.WAA02816@rulcmc.LeidenUniv.nl>
Path: arc1-ca.pugleaf.net!rulcmc.leidenuniv.nl!joost

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!rulcmc.leidenuniv.nl!joost
From: joost@rulcmc.leidenuniv.nl (joost witteveen)
Newsgroups: gnu.g++.help,comp.lang.c++
Subject: initialization of ostrstream
Date: 27 Nov 1995 16:37:47 -0500
Organization: Gatewayed from the GNU Project mailing list help-g++@prep.ai.mit.edu
Sender: daemon@cis.ohio-state.edu
Distribution: world
Message-ID: <199511272135.WAA02816@rulcmc.LeidenUniv.nl>