fstream question

I have this program that writes to a file to keep a track record, however, each time I open the file, the value that was in the file before is replaced by a new file.

Can anyone help me out?
umm set it up like this

fstream myfile ("trackfile.txt", ios::app)
myfile << "bla blab bla" << endl;


use the fstream with the ios::app parameter. This way it will take the stuff you want to put in the file and add it to the end of the file. Hope that helps.
I tried it, and it doesn't seem to work...

I'll insert some of my code
1
2
//Declaration
fstream recOfRandom;

1
2
//Open
recOfRandom.open("memory.txt");

1
2
//Insert Text
recOfRandom << "\ndepressed";

1
2
//Insert Text
recOfRandom << "\nrapper";

1
2
//Insert Text
recOfRandom << "\nregular";

1
2
//Insert Text
recOfRandom << "\nwarrior";
Last edited on
Try changing the open to this:

 
recOfRandom.open("memory.txt", fstream::in | fstream::out | fstream::app);
Both in and out methods in the file would not work, unless the file was first opened with out mode.

Check it out. Good luck :)
Topic archived. No new replies allowed.