0

I have created a roster program that accepts user input to create/write/delete information into and out of a specified text file. My issue now becomes wanting to create a lasting text file that isn't overwritten every time I re-run the program and am not sure if using fstream or a combination of of/ifstream is better practice, or if there is maybe a third option I missed when checking the reference docs.

Right now I am simply using: std::ofstream outfile("roster.txt"); which works, until I kill and re-run the program to which my text file is now wiped clean.

1 Answer 1

1

check out the append flag. it writes to the end of an existing file. http://www.cplusplus.com/doc/tutorial/files/

example here.

std::ofstream outfile("roster.txt" , ios::app) 
Sign up to request clarification or add additional context in comments.

3 Comments

also, you may want to parse your file when the program is opened before you accept any user input. Take the file and input it into your programs data structure. That way you could delete a previously stored record from the last time you ran the program. In that case, don't use append, and just rewrite your data into the file.
it should be , not |
Good catch @ArtemyVysotsky, I fixed it.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.