Public Group

This topic is 3011 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

Recommended Posts

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.

Share on other sites
Which part are you having difficulty with?
bool quit = false;do{ /* print file */ if( /* check input */ )   quit = true;}while( !quit );

Share on other sites
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);  }

Share on other sites
Never mind it works now it was just the way I was opening the text file.

Share on other sites
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. ;)

1. 1
2. 2
Rutin
24
3. 3
4. 4
JoeJ
18
5. 5

• 14
• 22
• 11
• 11
• 9
• Forum Statistics

• Total Topics
631766
• Total Posts
3002219
×

Important Information

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!