fstream query

Hi Everyone i am a newbie for c++, i just wanted to ask a question about fstream.

basically at the moment , I have a program that generates a 4 digit pin every 15 seconds . now that 4 digit pin generated are written inside a .txt file . the problem is the .txt file contains all the generated pin. meaning my file look like this at the moment

qwer
asdf
zxcv
tyui ---- represents the most recent generated pin

but i only wanted the most recent generated pin to be inside the .txt file . so i wanted to delete and overwrite those 15 seconds old pins . is that possible ??
I need your advice. Thank you
Open a filestream.
Write one PIN.
CLOSE the filestream.

Open the filestream again
Write one PIN.
CLOSE the filestream.

If you keep opening and closing then the default behaviour (unless you explicitly tell it to append) is exactly what you want - to overwrite.


Which is OK ... but surely you would achieve exactly the same aim by storing the PIN in a variable, rather than a text file?
Last edited on
Topic archived. No new replies allowed.