The following code works with gcc 4.4.
But gcc 4.7 will give assertion failure.
#include <assert.h>
#include <iostream>
#include <sstream>
using namespace std;
int main()
{
string input("abcdefg");
stringstream iss(input);
ostringstream oss;
oss << iss.rdbuf();
assert (!iss.eof());
(void) iss.peek();
assert (iss.eof());
// the following assertion will fail with gcc 4.7
assert( streamoff(iss.tellg()) ==
streamoff(input.length()) );
return 0;
}
In gcc 4.7, if the istream has reached EOF, tellg() will return -1. no pubseekoff() nor seekoff() will be called In gcc 4.4 it is not a problem.
Which is the supposed to be behavior, gcc 4.4 or gcc 4.7? Why?