This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
c++/9925: ostrstream (buf, size) << "..." does not work properly
- From: Pawel dot Pilarczyk at math dot gatech dot edu
- To: gcc-gnats at gcc dot gnu dot org
- Date: 3 Mar 2003 19:19:33 -0000
- Subject: c++/9925: ostrstream (buf, size) << "..." does not work properly
- Reply-to: Pawel dot Pilarczyk at math dot gatech dot edu
>Number: 9925
>Category: c++
>Synopsis: ostrstream (buf, size) << "..." does not work properly
>Confidential: no
>Severity: non-critical
>Priority: low
>Responsible: unassigned
>State: open
>Class: sw-bug
>Submitter-Id: net
>Arrival-Date: Mon Mar 03 19:26:00 UTC 2003
>Closed-Date:
>Last-Modified:
>Originator: Pawel Pilarczyk
>Release: gcc version 3.2.2
>Organization:
>Environment:
The environment does not matter - I have the same with DJGPP for DOS, Linux Red Hat (gcc 3.1 and 3.2), and on SUN OS, e.g.:
g++ -v
Reading specs from /usr/local/bin/../lib/gcc-lib/sparc-sun-solaris2.9/3.2.2/specs
Configured with: ../configure --prefix=/usr/local/encap/gcc-3.2.2 --with-gnu-as=/usr/local/bin/as --with-gnu-ld=/usr/local/bin/ld --disable-nls
Thread model: posix
gcc version 3.2.2
>Description:
The code
char buf [100];
ostrstream (buf, 100) << "..." << ends;
cout << buf;
produces output that looks like "0x10d48"
instead of what I expect (namely, "...").
Many other compilers work fine,
e.g. Sun WorkShop C++ Compiler 5.0 or GCC 2.96.
>How-To-Repeat:
#include <iostream.h>
#include <strstream.h>
int main (void)
{
char buf [100];
// the following works fine in GCC 2.96 and other
// compilers, but fails in GCC 3.1 and 3.2
ostrstream (buf, 100) << "This is OK." << ends;
cout << buf << endl;
// the following works fine in any compiler
ostrstream s (buf, 100);
s << "This is OK." << ends;
cout << buf << endl;
return 0;
} /* main */
>Fix:
To get around the problem, I used the following code instead:
char buf [100];
ostrstream s (buf, 100);
s << "..." << ends;
cout << buf;
>Release-Note:
>Audit-Trail:
>Unformatted: