PRB: istream::seekg() Does Not Reset EOF StateLast reviewed: July 31, 1997Article ID: Q146445 |
The information in this article applies to:
SYMPTOMSThe istream::seekg() function does not reset the EOF (end of file) state when the stream pointer is already at EOF.
RESOLUTIONTo work around this problem, call ios::clear() for the stream before calling istream::seekg().
STATUSThis behavior is by design.
MORE INFORMATIONYou don't need to call clear(), if the stream pointer is not already at EOF.
Sample Code
/* Compile options needed: None */ // Input: A file with the name test.txt containing some characters. #include <fstream.h> #include <assert.h> void main() { fstream in("test.txt", ios::in); char c; int i = 0; // Count characters in file while (in.get(c)) ++i; assert(in.eof()); // Reset read pointer to beginning of file in.clear(); in.seekg(0, ios::beg); // Check that file can now be read. // Fails without the in.clear() statement above. assert(!in.eof()); } Keywords : CPPIss Version : 4.0 Platform : NT WINDOWS Issue type : kbprb |
================================================================================
© 1998 Microsoft Corporation. All rights reserved. Terms of Use. |