Stream Operations in Binary Mode

There are many situations in which text mode isn’t appropriate or convenient, and it can sometimes cause difficulties. The transformation of newline characters into two characters on some systems and not others makes relative seek operations unreliable for programs that are to run in both environments. By using binary mode, you avoid these complications and make the stream operations much simpler. You’ve already seen how to open a stream in binary mode: you just need to specify the open mode flags appropriately. You can read and write a file in binary mode using functions that you have already seen, put() and get(). Let’s try it in an example.

We can write a program that will copy any file. The copying can be ...

Get Beginning C++ now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.