I'm opening a file and reading to the end of it. Then I want to go back to the beginning to read some other data. I wrote this code:
Tracing the code is: for the first time, "while" loop is done completely. Then I close the file and open it again. in the next loop ("for" loop), the program does not enter the "while" loop. That means it is stuck at the end of the file. Any idea? thanks,
Code:
ifstream fin2( "dictionary.txt" );
if ( !fin2.is_open() ) {
std::cerr << "failed to open dictionary.txt\n";
exit( 1 );
}
for ( ..... ) {
while(!fin2.eof()) {
getline( fin2, line );
.....
}
fin2.close();
fin2.open("dictionary.txt");
}
Comment