C++ file read endfinte loop

Started by
3 comments, last by Captain P 13 years, 12 months ago
How can I make a file be read from begining to end and back again tell I exit the program? I want to display the text in a file continusley. Like say I load a txt file I read its contents from top to bottom but then I want it to start at the top again ect tell I exit the program.
Advertisement
Which part are you having difficulty with?
bool quit = false;do{ /* print file */ if( /* check input */ )   quit = true;}while( !quit );
this is an inner loop so I have to use the if statment but I kind of figured this should work but its not displaying anything at all

if(!dataFile.eof()){  dataFile.getline(fileInput,TSize);   cout<<fileInput;}  else  {   dataFile.clear();   dataFile.seekg(0L,ios::beg);  }
Never mind it works now it was just the way I was opening the text file.
Read the file once, store it's content in memory, and then display that ad infinitum. Accessing memory is more efficient than accessing the hard-drive.

That may not be an issue for a small toy program, but it's something to keep in mind for real-life scenario's. Just saying. ;)
Create-ivity - a game development blog Mouseover for more information.

This topic is closed to new replies.

Advertisement