Document Summary

#include ifstream fsin; fsin. open("fname. txt") connects stream fsin to the external file "fname. txt fsin. close() disconnects the stream and associated file. fsin >> c; //behaves just like cin. #include ofstream fsout; fsout. open("fname. txt") connects stream fsout to the external file. "fname. txt". fsout. close() disconnects the stream and associated file. fsout << c; //behaves just like cout. // reads three numbers from the file numbers. dat, // sums the numbers, and writes the sum to the file. // declare variables and read in the data (3 numbers) int first, second, third; input_stream >> first >> second >> third; // write the data to the output file output_stream << "the sum of the first 3\n" // close the input and output files input_stream. close(); output_stream. close(); return 0; << "is " << (first + second + third) File i/o: example 1. 2 char next; input_stream. get(next); while (! input_stream. eof()) cout << next; output_stream. put(next); input_stream. get(next); input_stream. close(); output_stream. close(); return 0; // declare the input and output streams ifstream input_stream; ofstream output_stream;

Get access

Grade+20% off
$8 USD/m$10 USD/m
Billed $96 USD annually
Grade+
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
40 Verified Answers
Class+
$8 USD/m
Billed $96 USD annually
Class+
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
30 Verified Answers

Related Documents