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.

    1. Open a text file named output.txt for output (use ofstream).

    2. Rewrite the output for() loop to output to the above file rather than cout.

    3. Run your program and verify the results in output.txt.

  • How would you change your program to append to output.txt each 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.

    1. Create a new variable of type ifstream using the text file named input.txt.

    2. Rewrite the input while() loop to read lines from your new variable rather than cin.

    3. Run your program and verify the results.

  • Rewrite the while() loop condition to check the input file for remaining lines.

    1. Automatically read all lines in the file (without asking the user)

  • Submission Form

  • 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?