In this lab, we’ll do some exercises with I/O streams.
The files for this lab are available in ~cs253/pub/Labs/IOLab.
Your Lab assignment is to modify the number.cc class and modify.cc class so that it fulfils the requested requirements at the end of each part. You will get the mark of recitation if you could succeed in one of them. I will upload the solution at the end of the week.(After Friday's recitations.)
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.
Consider modify.cc. It copies its input file to its output file, replacing all instances of “Amin” with “Jack”.
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: 2011-10-23T23:13 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 |