Having a text file with a few characters (lets say 10), you can try to read 1000 characters from it.
char *buf = new char[1000];
ifstream in("in.txt");
in.read(buf, 1000);
This, of course, will set the eofbit flag (and the failbit too), however, you will be able to obtain the desired characters.
Now, suppose you want to read the file again (from the beginning):
in.seekg(0); // Sets input position indicator.
in.read(buf, 100); // Try to read again.
This does not work: because if you call:
int count = in.gcount() // Charecters readed from input.
you will notice that count == 0
. Meaning it has not read anything at all.
Hence the question: How can you rewind the file after you get to the end of the file?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…