All About EOF (2012)

All About EOF (2012)

If you create a text file using Notepad on Windows, or Vim on Linux, or any other editor/OS combination you fancy, that file will nowhere in it contain a special character marking the end-of-file. If you open the file using the Windows Notepad utility, you will see this:

Both lines of text are displayed, with the Control-Z character between them – Notepad does not know about Control-Z as an end-of-file marker at all. Here’s the canonical way to read a text file in C++:

If you compile and run this file on Windows, you will see that the Control-Z is treated as an end-of-file marker; the output is:

However, if you open the file in binary mode by making this change:

The Control-Z character is only treated as being special in text mode (the default) – in binary mode, it is just treated as any other character.

Source: latedev.wordpress.com