Article ID: 146445
Article Last Modified on 7/5/2005
/* 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: kbprb kbcpponly kbcompiler KB146445