CS 171 Chapter Notes - Chapter 9: Leading Zero, Random Access, String Orchestra
50 views4 pages
15 Mar 2017
School
Department
Course
Professor
Document Summary
To read or write disk files, you use objects of type fstream, ifstream, or ofstream. To access a disk file, you need to open a file variable. Ifstream is for input, ofstream is for output, and fstream is for both input and output. Must include header file fstream to use file variables: must open a file to read anything from it, give the name of the disk file to open it. Input_data >> s; // read a word: getline(input_data, s); // read a line. Read single characters with the get function (with char ch): If a character is read and you regret reading it, you can unget it such that the next input operation can read it again. You can only unget one character at a time: called one-character lookahead, olde(cid:396) i(cid:373)ple(cid:373)e(cid:374)tatio(cid:374)s of the st(cid:396)ea(cid:373) li(cid:271)(cid:396)a(cid:396)(cid:455) do(cid:374)"t have the u(cid:374)get (cid:373)e(cid:373)(cid:271)e(cid:396) fu(cid:374)(cid:272)tio(cid:374). If this is the case, use the put_back function. Fail function tells you whether input has failed.
Get access
Grade+
$40 USD/m
Billed monthly
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
10 Verified Answers
Class+
$30 USD/m
Billed monthly
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
7 Verified Answers