or the following code:
#include <iostream>
#include <sstream>
using namespace std;
int main() {
istringstream iss("a");
iss.get();
cout << iss.tellg() << endl; // 1
cout << iss.fail() << endl; // 0
}
I'd expect the result be -1,1 not 1, 0.
tellg will first construct a sentry and then check fail().
according to
http://eel.is/c++draft/istream::sentry#2
If is.rdbuf()->sbumpc() or is.rdbuf()->sgetc() returns traits::eof(), the function calls setstate(failbit | eofbit) (which may throw ios_base::failure).
so fail() should be true, and tellg should return -1.