🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

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

Re: initialization of ostrstream

#837
From: Kit Kauffmann
Date: Mon, 27 Nov 1995 15:38
49 lines
1859 bytes
In article <199511272135.WAA02816@rulcmc.LeidenUniv.nl> joost@rulcmc.leidenuniv.nl (joost witteveen) writes:
>From: joost@rulcmc.leidenuniv.nl (joost witteveen)
>Subject: initialization of ostrstream
>Date: 27 Nov 1995 16:37:47 -0500

>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


You are missing an ends (insertor for the string terminator)



Kit Kauffmann - kitk@mudshark.sunquest.com
AKA 73363,447 (Compu$erve)

Finger me for my public key
Technical Details
Message-ID: <kitk.1993.000FA2C3@mudshark.sunquest.com>
Path: arc1-ca.pugleaf.net!news.sunquest.com!kitk!kitk
References: <199511272135.WAA02816@rulcmc.LeidenUniv.nl>

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!news.sunquest.com!kitk!kitk
From: kitk@mudshark.sunquest.com (Kit Kauffmann)
Newsgroups: gnu.g++.help,comp.lang.c++
Subject: Re: initialization of ostrstream
Date: Mon, 27 Nov 1995 15:38:02
Organization: Sunquest
Distribution: world
Message-ID: <kitk.1993.000FA2C3@mudshark.sunquest.com>
References: <199511272135.WAA02816@rulcmc.LeidenUniv.nl>
NNTP-Posting-Host: kkauffma.sunquest.com
X-Newsreader: Trumpet for Windows [Version 1.0 Rev A]