COP 3014 Recitation - Week 8

Object Oriented File operations.

Part 1
a) Create a new project
b) Go to your documents folder / Visual Studio / project name / project name
c) Create a file in this folder named "input.txt" and add a number to the file contents, then save the file
d) Type this file in Visual Studio and run the program.
e) You should now also see a new file output.txt in the same folder

Part 2
a) Modify your program, change "writesentence(outputfile)" to "writesentence(cout)", run your program
b) Change it back
c) Change readinteger(inputfile) to readinteger(cin), run your program
d) Combine parts a and c, run your program
e) Why does your program still work?

Part 3
a) Change your code to write to and read from files again
b) Modify the writesentence function to take an extra string parameter, and write that string to the file instead of "Hello World"

Part 4
a) What's wrong with this file?
b) What's wrong with this file?
c) What's wrong with this file?
d) What's wrong with this file?
e) What's wrong with this file?

Program examples