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
that’s a wrapper around an
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.
fstreamto 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:
getlinereads into a C++
istream::getlinereads into a C-style character array.
Change modify.cc to modify a single file in place. That is, the program should only take a single filename argument.
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.