From: "David Lee" Newsgroups: comp.os.msdos.djgpp Subject: seekg() bug Date: Sat, 5 Aug 2000 13:43:33 +0800 Organization: IMS Netvigator Lines: 41 Message-ID: <8mg9j5$fis3@imsp212.netvigator.com> NNTP-Posting-Host: wtstnt04068.netvigator.com X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 5.00.2615.200 X-MimeOLE: Produced By Microsoft MimeOLE V5.00.2615.200 To: djgpp AT delorie DOT com DJ-Gateway: from newsgroup comp.os.msdos.djgpp Reply-To: djgpp AT delorie DOT com I opened a fstream object and tried to position the file pointer with seekg (). I found that seekg () always worked as long as eof () was not encountered. Once eof () holds, it would appear to work as usual, but subsequent reading from the fstream object were wrong. Any idea? Here is what I mean: #include void main () { fstream f ("dummy", ios::out | ios::bin); f.write ("0123456789", 10); f.close (); f.open ("dummy", ios::in | ios::bin); f.seekg (4, ios::beg); char x; f.read (&x, 1); cout << x << endl; // print 4, as expected while (!f.eof ()) // goto end of file f.read (&x,1); // now f.eof () holds. f.seekg (7, ios::beg); f.read (&x, 1); cout << x << endl; // does **NOT** print 7 (in fact, it prints 4, the previous input). f.close (); }