So I have this homework that is due and I really have no idea how to go about doing this. Ideally some links to explaining what to do would be the most helpful so that I can actually learn how to do this but if someone just writes the program, that would work too. The question is:
1. Create a complete program that:
a. prompts a user to enter the name of an existing file.
b. If the file does not exist and or cannot be opened, the program should display an error message and quit.
c. If the file exists and can be opened, prompt the user for a new file-name.
d. If the new file name already exists, print a message telling the user that the file already exists and ask the user whether they want to APPEND
i. if the user enters ‘N’ for “NO”, print a message “Operation canceled by user” and quit
ii. otherwise, open the file for APPEND and copy all of the contents from the original file
e. If the file doesn’t already exist, create a new file with the name supplied by the user and copy the contents of the original file into it.
Wow thank you so much. If you could, could you clarify your use of getline? For example, on line 21, is the cin, fileName what allows you to change the name of the existing file? And can you also explain your use of flush? Is that the same as endl; ?
fileName is a string to store the name of the file the user wants to copy from. getline() allows you to take input with spaces too ("filename" vs. "file name").
endl is a manipulator that flushes the stream and prints a newline. flush only flushes the stream without printing a newline. I used it to make sure text was outputted to the screen.