ENGR 101 Lecture 16: File Streams

54 views2 pages
31 Mar 2015
School
Department
Course

Document Summary

Engr 101: introduction to computers and algorithms - lecture 16: file streams. If we include the fstream library by typing: #include then we can define new streams that can get input from, and direct output to, files. Fstream adds two new types: ifstream and ofstream. These stand for input file stream and output file stream respectively. An ifstream is a sub-type of istream and ofstream is a sub-type of of ostream so they can be used just like cin and cout. To read from a file you first must declare a new ifstream and open it. This is done with a line of the form: ifstream infile( thisfile. txt ); This line will open a file called thisfile. txt and create a new ifstream called infile to extract input from the file by lines like: infile >> x >> y; To write to a file you first must declare a new ofstream and open it.

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