• We’re currently investigating an issue related to the forum theme and styling that is impacting page layout and visual formatting. The problem has been identified, and we are actively working on a resolution. There is no impact to user data or functionality, this is strictly a front-end display issue. We’ll post an update once the fix has been deployed. Thanks for your patience while we get this sorted.

Using Delimiter EOF :: C++

kuphryn

Senior member
Hi.

I am working on a small practice program for a C++ class. I need to implement a way to delimite using EOF. The user can break out of a while, for example, with ctrl-d (dos) or ctrl-z (unix).

What is the best way to implement something like that?

I have tried this:

while((num = cin.get()) != EOF) // from Deitel
{}

The above does not work.

Thanks,
Kuphryn
 
Hmm, I have always used eof on an actual file controller. Such as:
while( !file_input.eof() )
{}
where file_input is of type ifstream.

For console input, I have used
while( cin && cin.peek()!='\n' )
{}
to check if there is still stuff in the stream, and it is not a new line.

Hope it helps.
 
Back
Top