O'Reilly logo

C++ Primer Plus by Stephen Prata

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

Writing to a Text File

For file output, C++ uses analogs to cout. So to prepare for file output, let’s review some basic facts about using cout for console output:

• You must include the iostream header file.

• The iostream header file defines an ostream class for handling output.

• The iostream header file declares an ostream variable, or object, called cout.

• You must account for the std namespace; for example, you can use the using directive or the std:: prefix for elements such as cout and endl.

• You can use cout with the << operator to read a variety of data types.

File output parallels this very closely:

• You must include the fstream header file.

• The fstream header file defines an ofstream class for handling output.

• You need to declare ...

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