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?
This is a discussion on I\O Copy & Delete within the C++ Programming forums, part of the General Programming Boards category; thats say there are two files file abc.txt file def.txt and i wann delete the contents in abc.txt and copy ...
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");
Just Google It. √
(\ /)
( . .)
c(")(") This is bunny. Copy and paste bunny into your signature to help him gain world domination.
Look up unlink(). It's in cstdlib I believe.
Or, you could use remove() in cstdio.
i dont find there is rename for cstdio @@Originally Posted by Hunter2
In cstdio:
Removes specified file. Returns non-zero on failure.Code:int remove(const char* filename);
u mean like this?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.