S
Simon Pryor
I am having some strange problems using std:stringstream.
The simple stuff works okay, but trying to use:
std:stringstream::str(const std::string&)
or:
std:stringstream:stringstream(const std::string&)
Gives some weird results on both Solaris & Linux.
Either that or I'm missing something. I've made a simple program to
demonstrate the problem:
-------------cut-as-ostringstreambug.cc---------------------------
#include <string>
#include <iostream>
#include <sstream>
int main(void)
{
int rc = 0;
std:stringstream oss1;
oss1 << "foo";
oss1.str(std::string());
if (oss1.str() != std::string(""))
{ ++rc; std::cout << __LINE__ << ": Got \""
<< oss1.str() << '\"' << std::endl; }
std:stringstream oss2(std::string("foo"));
oss2 << "bar";
if (oss2.str() != std::string("foobar"))
{ ++rc; std::cout << __LINE__ << ": Got \""
<< oss2.str() << '\"' << std::endl; }
std:stringstream oss3;
oss3 << "foo";
oss3.str(std::string("bar"));
oss3 << "foo";
if (oss3.str() != std::string("barfoo"))
{ ++rc; std::cout << __LINE__ << ": Got \""
<< oss3.str() << '\"' << std::endl; }
return rc;
}
--------------------cut-end----------------------------------------
On Solaris:
CC -V
CC: WorkShop Compilers 5.0 98/12/15 C++ 5.0
CC -o ostringstreambug ostringstreambug.cc
ostringstreambug;echo $?
11: Got ""
16: Got "bar"
23: Got "foo"
3
On Linux:
g++ -v
gcc version 3.2.2
g++ -o ostringstreambug ostringstreambug.cc
ostringstreambug;echo $?
16: Got "bar"
23: Got "foo"
2
Now, I would expect to see no output and a return value of 0 on all
machines.
The only thing I can think of is that there is some sort of "freezing" the
way there was with the old "char* ostrstream::str()" stuff, but I don't
find anything that documents the intended behaviour.
Can anyone help?????????? please????
--
+------------------------------------------------------------------
| Simon Pryor, mailto:[email protected]
| Alcatel Bell Space N.V.
| Berkenrodelei 33, phone: +32 3 829 5130
| B-2660 Hoboken, Belgium. fax: +32 3 829 5502
+------------------------------------------------------------------
The simple stuff works okay, but trying to use:
std:stringstream::str(const std::string&)
or:
std:stringstream:stringstream(const std::string&)
Gives some weird results on both Solaris & Linux.
Either that or I'm missing something. I've made a simple program to
demonstrate the problem:
-------------cut-as-ostringstreambug.cc---------------------------
#include <string>
#include <iostream>
#include <sstream>
int main(void)
{
int rc = 0;
std:stringstream oss1;
oss1 << "foo";
oss1.str(std::string());
if (oss1.str() != std::string(""))
{ ++rc; std::cout << __LINE__ << ": Got \""
<< oss1.str() << '\"' << std::endl; }
std:stringstream oss2(std::string("foo"));
oss2 << "bar";
if (oss2.str() != std::string("foobar"))
{ ++rc; std::cout << __LINE__ << ": Got \""
<< oss2.str() << '\"' << std::endl; }
std:stringstream oss3;
oss3 << "foo";
oss3.str(std::string("bar"));
oss3 << "foo";
if (oss3.str() != std::string("barfoo"))
{ ++rc; std::cout << __LINE__ << ": Got \""
<< oss3.str() << '\"' << std::endl; }
return rc;
}
--------------------cut-end----------------------------------------
On Solaris:
CC -V
CC: WorkShop Compilers 5.0 98/12/15 C++ 5.0
CC -o ostringstreambug ostringstreambug.cc
ostringstreambug;echo $?
11: Got ""
16: Got "bar"
23: Got "foo"
3
On Linux:
g++ -v
gcc version 3.2.2
g++ -o ostringstreambug ostringstreambug.cc
ostringstreambug;echo $?
16: Got "bar"
23: Got "foo"
2
Now, I would expect to see no output and a return value of 0 on all
machines.
The only thing I can think of is that there is some sort of "freezing" the
way there was with the old "char* ostrstream::str()" stuff, but I don't
find anything that documents the intended behaviour.
Can anyone help?????????? please????
--
+------------------------------------------------------------------
| Simon Pryor, mailto:[email protected]
| Alcatel Bell Space N.V.
| Berkenrodelei 33, phone: +32 3 829 5130
| B-2660 Hoboken, Belgium. fax: +32 3 829 5502
+------------------------------------------------------------------