hi, I am new to C++ and new to this forum, sorry for being a noob.
i and using Dev-C++ as my compiler
i need to know how i can erase a file using the fstream or some other command. I am creating a game, and I can open the file to load a saved game (.txt file), but when i try and save the to a .txt file I need it to erase it information first. heres the code for saving the program (which i am having problems with):
1 2 3 4 5 6 7 8 9 10 11 12
|
#include <iostream>
#include <fstream>
using namespace std;
int main () {
int money;
fstream myfile;
myfile.open ("save/moneyt.txt");
myfile << money;
myfile.close();
}
|
this code works just fine, just doesn't do what i want it to.
the file "save/money.txt" has "20" in it.
if "int money" is less than 10(lets say its 4 for example), once compiled and run, the program replace the 2 (from the 20 in original file) with '4' and then "save/money.txt" will have '40' in it, instead of '4' which is what i want
so really, my question is how do I delete the contents of the file first, so the program will write the new value in the .txt file?
any help would be great!