27 Nov 2018: Output to a File
-
The following program contains a typo. Please identify and correct it (hint: use bounds-checking).
-
Write C++ code to save the program output to a text file.
-
Open a text file named
output.txtfor output (useofstream). -
Rewrite the output
for()loop to output to the above file rather thancout. -
Run your program and verify the results in
output.txt.
-
-
How would you change your program to append to
output.txteach time your program is run, rather than overwriting it?
29 Nov 2018: Read Input from a File
-
Please review the following program.
-
You will be modifying the above program to read input from a text file instead of
cin.-
Create a new variable of type
ifstreamusing the text file namedinput.txt. -
Rewrite the input
while()loop to read lines from your new variable rather thancin. -
Run your program and verify the results.
-
-
Rewrite the
while()loop condition to check the input file for remaining lines.-
Automatically read all lines in the file (without asking the user)
-
-
Optional: The
getline()function takes an additional argument that specifies the field delimiter. How would you modify your program to read a comma-separated value (csv) file?