If I use filebuf::sungetc() at the beginning of a file, the result of the next sbumc() call is not allways the first character in the file:
#include <fstream> #include <iostream> using namespace std; int main() { ifstream infile("test.dat"); filebuf* inbuf=infile.rdbuf(); int res; //at beginning of file res=inbuf->sungetc(); res=inbuf->sungetc(); res = inbuf->sbumpc(); if ( res == EOF ) cout << "x" << endl; else cout <<(char) res << endl; res=inbuf->sungetc(); //at beginning on file res=inbuf->sungetc(); res=inbuf->sungetc(); res = inbuf->sbumpc(); if ( res == EOF ) cout << "x" << endl; else cout <<(char) res <<"-"<<res<< endl; } The first sbumpc returns the first character in the file, the second doesn't. I don't think that it is intended, that I have to do the bookkeeping about the number of sungetc() calls manually, to guarantee, that the sungetc() acts in a defined way. Cheer, Troban -- Summary: Two times filebuf::sungetc() at beginning of file gives undefined result Product: gcc Version: 4.0.2 Status: UNCONFIRMED Severity: normal Priority: P3 Component: libstdc++ AssignedTo: unassigned at gcc dot gnu dot org ReportedBy: trumsko at yahoo dot com GCC build triplet: i686-pc-linux-gnu GCC host triplet: i686-pc-linux-gnu GCC target triplet: i686-pc-linux-gnu http://gcc.gnu.org/bugzilla/show_bug.cgi?id=26907