tags:

views:

72

answers:

2

I have a C++ program that is reading in info from a file, that stores info seperated by "$$$$". An example of how the file looks is:

abc
bcd
$$$$
def
$$$$
qwe
gfh
$$$$

How can I detect the file has ended, without using the eof() function?

I have it set like this,

getline(sin,temp)
if (temp=="$$$$")
{
}

After reading the last set of four dollars, how can I check the next line to ensure another set of data isn't beginning, and that the file has ended? If the file has indeed ended, I plan on using a boolean flag to terminate the while loop.

+1  A: 

I'm not sure why you can't use eof() but you could get the file size first and then only read that many bytes.

Brian R. Bondy
its because of the architecture of my current program. I know I can redo it to make it better, but I don't have time for it right now, so I need to work with what I have.
xbonez
@xbonez: I can't see why using eof() would require you to re-architect your program...
Brian R. Bondy
@xbonez can you please tell us exactly what architecture constraints you have that prohibit using `eof()` ?
wilhelmtell
+7  A: 
while (getline(sin, temp))
{
    // use temp.
}

You will come out of loop once you are end of file.

Jagannath