A text stream will invoke translation of the system defined newline marker to a \n (on reading), and the reverse \n to system defined on writing.
A binary stream doesn't do this.
There is perhaps an implicit assumption that a file opened in text mode might actually consist only of printable characters and cursor control characters.
Salem
Posting Sage
11,531 posts since Dec 2005
Reputation Points: 5,862
Solved Threads: 953
The difference also depends on the operating system -- on *nix there is no difference between text and binary written files because *nix compilers make no translation of the '\n' character in either mode. That is, the file itself will contain the same information whether writting with a stream opened in text or binary mode.
That is not true for files writting by MS-DOS, MS-Windows, and MAC. I don't know about other operating systems such as RISC but I suppose it might be true. On MS-DOS/MS-Windows when a file is opened in text mode the '\n' is translated to "\r\n" when written to the file. MAC it is translated to '\r'. So when read back into the program the "\r\n" (or '\r') is transated back to just '\n'.
Ancient Dragon
Retired & Loving It
30,049 posts since Aug 2005
Reputation Points: 5,662
Solved Threads: 2,343
After all, a hard drive doesn't see chars, or ints, or doubles - it just sees bits. So it really doesn't matter what we output the data as in C++. Once it gets to the hard drive, it becomes bits, and then any program can interpret the data in the file any way it wants.
True, but that doesn't mean the program will interpret the data correctly. Example: move a file written in text mode on MS-Windows to *nix, then use a *nix text editor to read it. Or do the opposite -- move a text file writting on *nix to MS-Windows and use Notepad.exe to read it. In both cases the editor will mis-interpret the line feeds. In some cases the text editor may be smart enough to translate the file correctly, but most simple text editors such as Notepad.exe can not do that.
Ancient Dragon
Retired & Loving It
30,049 posts since Aug 2005
Reputation Points: 5,662
Solved Threads: 2,343