下面的代码工作用gcc 4.4。
但是GCC 4.7会给断言失败。
#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;
}
在GCC 4.7,如果istream的已经达到EOF,所以tellg()将返回-1。 没有pubseekoff()也不seekoff()将被称为在GCC 4.4它是没有问题的。
这是应该的行为,GCC 4.4或4.7的gcc? 为什么?