September 22nd, 2003, 01:42 PM
inputing into files
Here is my question. I have a program where I have 2 functions. The first function (main) gathers two inputs of type string. I also remove the origional file so as to get rid of any left over text.
The other function is able to take one string at a time and place it into a file. Now the problem is when I run the program and I open up the file, only the last string is in the file, and not both.
Here is the code.
using namespace std;
void f1(string text)
cout<<"enter string 1"<<endl;
cout<<"enter string 2"<<endl;
I understand that I could make f1 just take 2 strings but I need to do it this way.
This message is a natural product made from recycled electrons. The slight
variations in spelling and grammar enhance its individual character and
beauty and in no way are to be considered flaws or defects.
September 22nd, 2003, 02:21 PM
The problem is here:
>> op.open("output.txt",ios:: out);
You're opening the file in output mode (which overwrites the previous contents). What you want to do is open in append mode.
op.open("output.txt",ios:: out | ios::append);
See http://www.developer.com/net/cplus/a...0919_2119781_2 for more on file permissions.
Up the Irons
What Would Jimi Do? Smash amps. Burn guitar. Take the groupies home.
"Death Before Dishonour, my Friends!!" - Bruce D ickinson, Iron Maiden Aug 20, 2005 @ OzzFest
Down with Sharon Osbourne
"I wouldn't hire a butcher to fix my car. I also wouldn't hire a marketing firm to build my website." - Nilpo
September 22nd, 2003, 02:34 PM