O'Reilly logo

Just Enough C/C++ Programming by Guy W. Lecky-Thompson

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Binary Input and Output

You can also write variables to files as binary values—an integer (for example) will remain an integer. Some advantages of space and processing time are apparent: For example, an integer takes two bytes to store in memory, but this could expand to up to five bytes of characters when written to a file.

Using binary representation keeps the size of the stored integer down to two bytes, a clear advantage if there are many numbers in a file. The same analysis can be performed on floating-point numbers of large accuracy. Storing them as binary data will be much more space efficient than storing them as text. The gain is in the size of file and a boost in speed and efficiency when reading or writing the file.

A binary file can ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required