seek bug in stringstream?

Lars Gullik Bjønnes larsbj@lyx.org
Sat Apr 1 00:00:00 GMT 2000


Ok, the cvs seems a lot better now, but still:

#include <iostream>
#include <sstream>
#include <strstream>
#include <fstream>

int main()
{
        using namespace std;

        ostringstream ost;
        cout << ost.tellp() << endl;
        ost << "Hello";
        cout << ost.tellp() << endl;
        ost << " World!";
        cout << ost.tellp() << endl;

        ostrstream ost2;
        cout << ost2.tellp() << endl;
        ost2 << "Hello";
        cout << ost2.tellp() << endl;
        ost2 << " World!";
        cout << ost2.tellp() << endl;

        ofstream of("tmp");
        cout << of.tellp() << endl;
        of << "Hello";
        cout << of.tellp() << endl;
        of << " World!";
        cout << of.tellp() << endl;
}                                           

gives:

-1
5
12
0
5
12
0
5
12          

This patch to sstream.tcc makes stringstream behave like fstream and
strstream, I have no idea if this change have other impacts...

--- /home/larsbj/Development/libstdc++/bits/sstream.tcc Fri Mar 24 01:41:56 2000
+++ /local/larsbj/egcs/libstdc++-v3/bits/sstream.tcc    Fri Mar 24 04:11:01 2000
@@ -123,8 +123,7 @@
       bool __testout = __mode & ios_base::out && _M_mode & ios_base::out;
       bool __testboth = __testin && __testout && __way != ios_base::cur;

-      if (((__testin && !__testout) || (__testout && !__testin) || __testboth)
-         && _M_buf_size)
+      if (((__testin && !__testout) || (__testout && !__testin) || __testboth))
        {
          char_type* __beg = _M_buf;
          char_type* __curi = NULL;       


The testcases will bark on this though...

	Lgb


More information about the Libstdc++ mailing list