In many projects, I saw that data object/structure are written into file in binary mode, and then retrieve them back from the file in binary mode again.
I wonder why
Only a few operating systems are affected by the choice between binary and text mode. None of the Unix or Linux systems do anything special for text mode—that is, text is the same as binary.
Windows and VMS in particular transform data in text mode. Windows transforms \n
into \r\n
when writing to a file and the converse when reading. VMS has a file record structure to observe, so in the default mode, it translates \n
into a record delimiter.
Where it is different, binary is faster. If it is not different, it makes no difference.