Microsoft KB Archive/146445

= PRB: istream::seekg Does Not Reset EOF State =

Article ID: 146445

Article Last Modified on 7/5/2005

-

APPLIES TO


 * Microsoft Visual C++ 4.0 Standard Edition
 * Microsoft Visual C++ 4.1 Subscription
 * Microsoft Visual C++ 4.2 Enterprise Edition
 * Microsoft Visual C++ 4.2 Professional Edition
 * Microsoft Visual C++ 5.0 Enterprise Edition
 * Microsoft Visual C++ 5.0 Professional Edition
 * Microsoft Visual C++ 6.0 Enterprise Edition
 * Microsoft Visual C++ 6.0 Professional Edition
 * Microsoft Visual C++ 6.0 Standard Edition

-



This article was previously published under Q146445



SYMPTOMS
The istream::seekg function does not reset the EOF (end of file) state when the stream pointer is already at EOF.



RESOLUTION
To work around this problem, call ios::clear for the stream before calling istream::seekg.



STATUS
This behavior is by design.



MORE INFORMATION
You 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.


 * 1) include 
 * 2) include 

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: kbprb kbcpponly kbcompiler KB146445

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.