I was using some code to write int's defined by user to a file but found when you use

myfile.open ("lover_names.txt");
    myfile << firstLover << " " << secondLover << " " << lovePercent << "%\n\n";

It replaces the other text in the text file, the answer will most likely be simple but i don't know it, Help ASAP?

The answer is in the open() function -- see the flags for the second argument. If you want all writes to go at the end of the file the second argument should be ios::ate.

Or you could do seekp() first to set the file pointer to end-of-file. But ios::ate is a lot easier.

Thanks but i'm still stuck, where would i put ios::ate?

myfile.open ("lover_names.txt");
    myfile << ios::ate << firstLover << " " << secondLover << " " << lovePercent << "%\n\n";

This does the same as before, only keeps one thing in but this time it always has a 2 infront of the name etc, please correct me and show me where to put w.e

>> where would i put ios::ate?
You didn't read my post very carefully did you? Or the link I posted ??? myfile.open ("lover_names.txt". ios::ate);

also, it might help to have:

myfile.open ("lover_names.txt", ios::ate | ios::app);

So it automaticly seeks the end of the file before you begin writing to it.

Sorry i read wrong,

I got errors with your code, it said missing ) before ios, so then i put ("lover...")(ios::..); etc and still got errors,

Then i put..

myfile.open ("lover_names.txt"); ios::ate;
    myfile << firstLover << " " << secondLover << " " << lovePercent << "%\n\n" << ios::ate;

But the same thing is happening, no multiple lines etc!?

how long have you been programming now? Is this your first semester? Look at what I posted and compare it with what you did. Everybody makes mistakes, but you have to learn to recognize the simple errors you make.

>>But the same thing is happening, no multiple lines etc!?
Of course not because you didn't change the *.exe file. The compiler doesn't replace the *.exe file when there are compile or link errors. There's no point running the old program until all errors are currected.

You have to include the parameters in the open() function.
When opening the file just have:

myfile.open ("lover_names.txt", ios::ate | ios::app);

instead of

myfile.open ("lover_names.txt"); ios::ate;

That is all, then you can simply just write to the end of the file by using:

myfile << "Text";

Thanks william! Now that bit works, just i still get the "2" on every line, can i get rid of that?

@ William - Cool, i wish we could get programming classes at our age at school though :/

Yeah ino, I'm learning flash in I.T atm but i know more about computers than my I.T teacher.. I've took something called CIDA for year 10 and thats to do with computers etc :) BUT STILL NO PROGRAMMING LESSONS

This question has already been answered. Start a new discussion instead.