delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1998/10/26/04:31:50

From: Koen_Van_Herck AT xircom DOT com
X-Lotus-FromDomain: XIRCOM
To: djgpp AT delorie DOT com
Message-ID: <C12566A9.00333F43.00@hurricane.xircom.com>
Date: Mon, 26 Oct 1998 10:28:07 +0100
Subject: strstream str() problem
Mime-Version: 1.0
Reply-To: djgpp AT delorie DOT com

Hi,

I'm using the gpp-e11b (egcs) alpha and have a problem with strstreams.

The following code

int main()
{
   for (int i = 0; i < 2; i++)
   {
      strstream os;
      os << "test ";
      if (i == 0) os << "first";
      os << endl;
      string s = os.str();
      cout << s;
   }
}

fails to properly terminate the string s. (output is "test
first\ngarbagegarbage...test\ngarbage..." It seems the str() function does
not append the '\0' terminator to the string correctly. Is this a bug, or
am I doing something wrong ?

Thanks,
Koen.


- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019