Opening files in binary mode

This is a discussion on Opening files in binary mode within the C++ Programming forums, part of the General Programming Boards category; I just what to ask what's the point from opening files in binary mode, and what are the uses for ...

Well english isn't my first language, (it's instead a useless language called danish which only 5 milion people speak!!) so if you think my grammar SUCKS (it does by the way) than you're more then welcome to correct me.
Hell I might even learn something

>I just what to ask what's the point from opening files in binary mode
It can be more efficient both with speed and space usage. You can store values directly instead of having to write them as strings of characters and convert them back when reading from the file as well. There are many uses, but the general consensus is to use text when possible and binary when necessary because binary files effectively kill portability.

>Are we back to "implementation-defined" where portability is concerned?
Something like that.

The layout of a binary file is a direct mapping of the data, it depends an many different platform specific details. The number of bytes, byte order, and representation are all factors. And that is just for integer values, floating point values are even worse, the same size and byte order factors exist, but floating-point values vary in both the number of bits for the mantissa as well as the exponent and the data may not even be in base ten. For structures, you have to consider the platform dependent alignment and padding of the data.

So you can't be sure that a binary file can be transferred to another compiler, much less another machine. Now, you can read and write the binary data manually, but that is usually more effort than it's worth, so text files are preferred.