fstream

Feb 3, 2015 at 8:12pm
How does one create a text file without replacing the last one every time the program is compiled? Say for example you made a text document for a person to store his/her ID and password which is done using the command prompt so that the program can read from that file and then granting access to the person when logging in. But every time the program is compiled it replaces that file and erases the login data (ID/password) within.

ofstream write;
write.open("Account.txt");

I know this ain't much but you can see the point I'm trying to make



Feb 3, 2015 at 8:17pm
Try:
write.open("Account.txt", fstream::ate);
Last edited on Feb 3, 2015 at 8:17pm
Feb 3, 2015 at 8:32pm
Nope... creates a new file. I was thinking of something like the program can look for the text file and if so then it does not create a new one. Like an IF statement.
Last edited on Feb 3, 2015 at 8:36pm
Feb 3, 2015 at 8:51pm
You need to use fstream::app. This will append to an existing file.
Feb 3, 2015 at 10:09pm
Thank you very much!
Topic archived. No new replies allowed.