O'Reilly logo

Beginning C++ by Ivor Horton

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

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 ...

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