#Infinitely looping file input test?

13 messages · Page 1 of 1 (latest)

rocky shadow
#

Hey everyone. I’m testing out file input for the first time. I have a .txt file of some lines and values I want to receive and use for a program to output. However, it seems to be using empty lines forever, which was not my intent. What can I do?

warped hatchBOT
#

When your question is answered use !solved to mark the question as resolved.

Remember to ask specific questions, provide necessary details, and reduce your question to its simplest form. For tips on how to ask a good question use !howto ask.

queen yoke
#

atleast, I think inFS.clear() would clear the EOF flag

rocky shadow
#

Don’t I have that at the very end of the loop?

#

At line 42

#

Oh you’re saying to NOT have .clear() because it’s clearing the EOF flag…

rocky shadow
#

It did not fix anything by deleting it ://

#

I realized my logic was bad. It needs to read THEN check if it’s eof(),

wicked atlas
#

I’d likely be better to instead use the return of the IO function itself coming from the ifstream then to use .eof() to detect if you’ve actually reached the end of the file.

#

At least in the loop here

#

But yes you are clearing the error state with .clear() which makes it so EOF is never visibly set to the loop.

wicked atlas