Lines
| Terms
| Notes
| In Java
|
2-4
| Various libraries
|
- fstream is the library containing file-related classes
- sstream is the library containing string-based stream classes
- iomanip is the library containing types related to manipulating the format of streams
|
|
19
|
|
- To declare an array of class objects, the class must have a default constructor
- Without a default constructor, how would all the lements be initiliazed?
- The common solution is to use an array of pointers to the objects and
create them as necessary
- This also proves to be a space saving tactic, as one does not declare
a slew of objects, only pointers
| In Java, this is the standard approach (or at least substutuing 'reference' for 'pointer'
|
22-23, 38-39, 58-59
| File open
|
- No runtime error results from Failure to open a file
- An internal status flag is set iwithin the stream object
- An implicit conversion operation to bool is defined within the stream — used as a boolean
the stream object returns true/false depending upon whether the stream is ready for I/O
| Java throws an exception when a file cannot be opened
|
75-79
|
- numeric to string conversion
ostringstream
|
- To maintain accuracy in our money calculations, we shun double (which generates round-off errors) and
instead represent our values as integers — in particular, as the monetary value expressed in cents.
- In this program, we have no need to convert our money values to string (the only thing we do with these values is output
them, and the << operator performs the conversion for us.
- However, for illustrative purposes, we provide code to show how one would take a numeric value (or any other value for
that matter), and transform it into a string using a
ostringstream
- An
ostringstream is a stream just like any other (cout or ofstream), except that the output
is 'written' to a string, rather than a file or the screen.
- The resulting 'output' can then be retrieved using the
str() member function of the
ostringstream object.
| The toString methid is used in Java to perform such conversions
|
77
| manipulators
| C++'s I/O streams have default formats for values sent to them-- e.g. the number of digits of precision for doublesr;
however there are times these formats are inappropriate, e.g. one might want to specfiy a minimum number of characters
for the diaply of a value (for purposes of tabular output). Manipulators are objects that provide the programmer with such facilities.
They are sent to an I/O stream to override the default behavior. In some case the manipulator operates only for the next item read/written;
in others, the effect of the manipulator persists until changed.
| Java provides formatted I/O methods (printf , format ) similar to C's scanf/printf functions.
|