thats say there are two files
file abc.txt
file def.txt
and i wann delete the contents in abc.txt and copy the contents in def.txt to abc.txt then delete the def.txt file
any function to do that?
Printable View
thats say there are two files
file abc.txt
file def.txt
and i wann delete the contents in abc.txt and copy the contents in def.txt to abc.txt then delete the def.txt file
any function to do that?
Delete - see if either foo.empty() or foo.clear() works, I don't have a compiler on this computer so I can't find out that answer for you
Copy - Don't know of a function but you could try something like this
Code:while (!infile.eof())
{
outfile << infile.get();
}
Try:
Code:#include <cstdio> //For rename()
#include <windows.h> //For DeleteFile() - Windows specific.
...
DeleteFile("abc.txt");
rename("def.txt", "abc.txt");
Look up unlink(). It's in cstdlib I believe.
Or, you could use remove() in cstdio.
i dont find there is rename for cstdio @@Quote:
Originally Posted by Hunter2
In cstdio:
Removes specified file. Returns non-zero on failure.Code:int remove(const char* filename);
u mean like this?Quote:
Originally Posted by sean_mackrory
system ("del abc.txt");
system ("ren def.txt abc.txt");
however i am trying to find other way out
but thank you all
And actually I had to correct myself, I got myself mixed up. system() is a bad idea when there are more portable options. Have a look at http://www.cprogramming.com/tips/ to find out why, but until then - just use the functions suggested to you above.