O'Reilly logo

C++ All-In-One For Dummies®, 2nd Edition by Jeff Cogswell, John Paul Mueller

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

Chapter 1. Filing Information with the Streams Library

In This Chapter

  • Seeing the need for a streams library

  • Using the right header files

  • Opening a file

  • Dealing with errors

  • Working with flags to customize your file opening

First things first. We've all heard of rivers and lakes and streams, and it's interesting just how many common words are used in computer programming. That's handy, because it lets us use words we already know with similar meaning, but it's also a bummer in that it's harder to impress strangers. While we don't have gluggerbumbles and plickershops in computer programming — words most people have never even heard of, mainly because we made them up — we do have streams!

Most programmers think of a stream as the same thing as a file. You know — a file that's stored on your hard drive or maybe on a floppy disk or Zip drive. But streams go beyond just files. A stream is any type of data structure that you stream your data into and out of in a sequence of bytes.

For example, if we open an Internet connection to a top-secret computer that stores all our top-secret data (ooooh), and we start putting our data on the remote computer, we might use a stream-based data structure. By that we mean we write the data in sequence one byte after another as the data goes over the Internet like a stream of water, reaching the remote computer. The data we wrote first gets there first and so on. It's kind of like a stream of water.

You can use the same approach for storing data into a file. Rather ...

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