I should point out first that I'm very new to C++: I can use functions cin, cout, getline and a few from the library string.h.
I am attempting to use ifstream to pull in text line by line from a txt file, which works.
However, when the file reader reaches the end of the file, I want it to start again from the top. This it won't do.
here is the code I'm using:
The seekg() function was suggested by a friend. I understand that it does something to the same pointer that getline() uses but I'm hazy on the details.Code:ifstream txtfile("Z.txt"); //access the txt file. //here goes all my program code... if ( txtfile.eof() ){ //when reader has reached the end of the txt file. txtfile.seekg(0,ios::beg); //reset getline() internal pointer. }
Anyway, it doesn't work.
Can anybody help me?



LinkBack URL
About LinkBacks


