The following code will behave differently depending if it’s compile with
gcc or dinkum lib.
#include <iostream.h>
#include <strstream.h>
int main(void) {
strstream a;
a.seekp( 0, ios::beg );
a << 2 ;
cout << a.tellp() << endl;
return 0;
}
With gcc lib output is 1 (size of stream), with dinkum output is -1. It
seems with dinkum lib the seek to the beginning of the stream puts the
stream into an error condition, who’s right gcc or dinkum.
According to my reading of the C++ standard, Dinkum is correct.
In your example, the underlying strstreambuf has no storage allocated until
you actually put something in it. The standard says “For a sequence to be
positioned, if its next pointer … is a null pointer, the positioning
operation fails”. So it is correct for the seekp to fail, which would put
the stream into the failed state.
In theory, you should check for a stream going into failed state after every
seek operation.
Rob Rutherford
“Mario Charest” postmaster@127.0.0.1 wrote in message
news:b9bp38$ne6$1@inn.qnx.com…
The following code will behave differently depending if it’s compile with
gcc or dinkum lib.
#include <iostream.h
#include <strstream.h
int main(void) {
strstream a;
a.seekp( 0, ios::beg );
a << 2 ;
cout << a.tellp() << endl;
return 0;
}
With gcc lib output is 1 (size of stream), with dinkum output is -1. It
seems with dinkum lib the seek to the beginning of the stream puts the
stream into an error condition, who’s right gcc or dinkum.