Run the program excerpted in Example 1.11 as written and then
Modify it so that it gets the filename from the user as an STL string fileName
before writing or reading. You need to use the function fileName.c_str()
to convert the string to a form acceptable to the open()
function.
Modify it so that it makes sure that the file specified by the user does not already exist (or that it is okay to overwrite if it does exist) before opening it for output.
Explain what happens if you read the individual numbers with variables of the wrong type (e.g., int
instead of float
or double
) in the "watch for errors" section.
Explain what happens if you read only with numerical variables and do not use the newstr
variable in the "watch for errors" block.
Do the same thing for the program in Example 1.14.
[ fromfile: filestreams.xml id: None ]
Generated: 2012-03-02 | © 2012 Alan Ezust and Paul Ezust. |