In this lab, we’ll do some exercises with I/O streams. The files for this lab are available in ~cs253/Labs/IO. You will modify code in these files.                 
Consider number.cc. It creates a class called Number
that’s a wrapper around an int
.
                
<<
works for Number
, even though operator<<
wasn’t defined for this class?
operator>>
. It doesn’t check for failure.
And, yet, it works properly for:
operator>>
so that it works properly for input such
as “one”, “two”, “three”, “four”, and “five”, as well as working
for all traditional numeric input that worked before.
fstream
to modify a file in place.                Consider modify.cc. It copies its input file to its output file, replacing all instances of “global” with “denial”.                 
Note the use of getline
. There are two versions of this function:
getline
reads into a C++ string.
Change modify.cc to modify a single file in place. That is, the program should only take a single filename argument.                 
Hints:
Improve operator>>
in number.cc even more:
If it encounters invalid input such as “zork”, it shouldn’t consume
the bogus input. It should fail, and leave things such that the next
read (assuming that the stream is put back into a good state) would
see “zork” again.
                
Modified: 2017-03-23T11:02                  User: Guest                  Check: HTML CSSEdit History Source |
Apply to CSU |
Contact CSU |
Disclaimer |
Equal Opportunity Colorado State University, Fort Collins, CO 80523 USA © 2015 Colorado State University |