> hours; If you specify a file for output, and that file already exists, the existing file will be deleted, and a new empty file will be created."> > hours; If you specify a file for output, and that file already exists, the existing file will be deleted, and a new empty file will be created.">
Download presentation
Presentation is loading. Please wait.
Published byJoel Crawford Modified over 6 years ago
1
Text Files All the programs you've seen so far have one thing in common: Any data the program uses or calculates is lost when the program ends. In order for the data to persist, it must be stored in a file on some type of device. Once the data is stored, it can be used in the future by the same program or other programs.
2
In order to use files for input or output in your program:
#include <fstream.h> For file output: Declare a variable of data type ofstream and associate the name of the file to be used: ofstream outfile( "output.txt" ); Use the name of the variable like you use cout: outfile << id << " " << total << endl; For file input: Declare a variable of type ifstream and associate the name of the file: ifstream infile( "data.txt" ); Use the name of the variable like you use cin: infile >> hours; If you specify a file for output, and that file already exists, the existing file will be deleted, and a new empty file will be created.
Similar presentations
© 2025 SlidePlayer.com Inc.
All rights reserved.