Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

What type does eof return?

Both cppreference.com and cplusplus.com say it’s int_type. But they don’t explain (at least I couldn’t find it, an neither could Bing Chat) what type it is. (I suppose it can be any signed integer type at least as wide as char and bool.)

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

The special value EOF needs to be of integer type that is wider than the corresponding character type, as it cannot be the same value as any character.

In common scenarios, but not all scenarios(!), it is -1.

The traits class template std::char_traits provides a corresponding type for the respective character types: https://en.cppreference.com/w/cpp/string/char_traits

For example, for char it is int. Which is platform-dependent, but at least 16 bits wide.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading