My file will compile and run for this assignment, but for some reason it will not locate the file that needs to be appended to. I know this is probably something very simple that I have missed but I can not figure it out and it is due tonight. Can someone please help me?
Here is what needs to be done:
Write a program that gives and takes advice on program writing. The program starts by writing a piece of advice to the screen and asking the user to type in a different piece of advice. The program then ends. The next person to run the program receives the advice given by the person who last ran the program. The advice is kept in a file, and the contents of the file change after each run of the program. You can use your editor to enter the initial piece of advice in the file so that the first person who runs the program receives some advice. Allow the user to type in advice of any length so that it can be any number of lines long. The user is told to end his or her advice by pressing the Return Key Twice. Your program can then test to see that it has reached the end of the input by checking to see when it reads two consecutive occurrences of the character.
what compiler are you using?
I wouldn't expect this to compile because you didn't use #include <string>
judging from your problem description you only need one file. You need to open the file for input, input the advice, close the file, reopen the file for output, output the new advice, then close the file.
I'm using VS2008 and pasting your code 'as is' failed to compile correctly. After adding a #include <string> it compiles, but then got caught up in the same place that you pointed out.
First of all are there any restrictions on what functionality and streams you have to use? I've always been a fan of using file handles. But since it's almost due I'll be sticking to your implementation.
Not necessarily looking into too much detail of the end implementation providing the desired output, I looked through this and found that with your logic and such it should work.
After a while I realized the issue might be that your program tried to open a file for reading that didn't already exist, and that the code you have only accounts for a case in which your original file from the start does exist. After adding a file input.txt into the project and some simple text like Hi this is a test. and running the code, it works. I then tested it further with a response to Please add any advice you have and press enter twice when completed being Don't forget to add an input file next time!!! :) .
Your current code will output to the text file something like Hi this is a test.Add an input file next time!!! :) in its current state (and my input), but that can be easily remedied by adding a newline character \n somewhere in there!
Hope I wasn't too late, and that you don't run into additional problems.