hi..is it possible clear data in a .dat file.
lets say my file initially has:
*******
my name is sujeet.
*******
Now i want to clear all that data and have my file data:
*******
sujeet is my name.
*******
is it possible?wat function to use?
hi..is it possible clear data in a .dat file.
lets say my file initially has:
*******
my name is sujeet.
*******
Now i want to clear all that data and have my file data:
*******
sujeet is my name.
*******
is it possible?wat function to use?
The same functions you used to write the file in the first place.
If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
If at first you don't succeed, try writing your phone number on the exam paper.
but how do i erase the data in the data file?
waht command?
ofstream out ("somefile", std::ios::trunc);
or to add to it but not delete
ofstream out ("somefile", std::ios::app);
just search google for a fstream reference.
By data file you mean a .txt file? You need to #include <fstream> so you can read/write from files, atleast on a console program. There is no "erasing" of other data, you just write over it.
scwizzo: I dont know if I misunderstood you, but <fstream> will read any file. Also, you can "erase" data from a file. Maybe not bits and pieces, but you can delete the whole thing, but then again if you can write it once, you can surely write the data to the file again.
If I were the OP I would get on cppreference.com and learn about file I/O. I had my problems with it, as everyone else did once or twice. I think a good reference would be a great place to start.