I asked about the mkdir command for dos, now I wanna know if it's possible to copy the file's. like the command copy in dos. If it is please fill me in on what it is.
Thanks
-Kavity
I asked about the mkdir command for dos, now I wanna know if it's possible to copy the file's. like the command copy in dos. If it is please fill me in on what it is.
Thanks
-Kavity
i'm not stupid, just a little short on brains.
Kav's game!
Featuring:
# - Goodguy mc goodguy
* - Bad guy mc badguy
$ - Princess Mc Cess
@ - Mcdonalds Mc chicken! mmmmmm
With fopen you can open files for reading and/or writing.
Open your source-file for reading and your destination-file for writing and use for example fgetc and fputc to get a byte from the source-file and to put it in the destination-file.
After that you can use fclose to close both files.
Perhaps this little piece of code may help.
FILE *in, *out;
unsigned char byte;
in = fopen ("myinfile.dat", "rb");
out = fopen ("myoutfile.dat", "rw");
while (!feof (in))
{
byte = (unsigned char) fgetc (in);
fputc ((int) byte, out);
}
fclose (in);
fclose (out);
Thanks, but I'd rather not have to use fopen. Is there any other way to do it?
-Kavity
i'm not stupid, just a little short on brains.
Kav's game!
Featuring:
# - Goodguy mc goodguy
* - Bad guy mc badguy
$ - Princess Mc Cess
@ - Mcdonalds Mc chicken! mmmmmm
In forum C Programming, topic File reading and writing, there Prelude gives some alternatives to this. I suggest you take a look at those.
Why won't you use fopen?
I don't really want to use fopen. The code is already almost written, it makes the directorys. And it's all done by using ofstream. And if I was to use fopen I would have to rewrite the code. I may do that later on, but for now I'm just wondering. Thanks anyways.
-Kavity
p.S.: I'll check that out.
i'm not stupid, just a little short on brains.
Kav's game!
Featuring:
# - Goodguy mc goodguy
* - Bad guy mc badguy
$ - Princess Mc Cess
@ - Mcdonalds Mc chicken! mmmmmm
if you use the system(char * ) command, you can make any msdos calls you want to and call copy yourself.
That would call the msdos system call copy, and copy file to newfolder.Code:system("copy file1.txt newfolder\\file1.txt");
Copying is quite simple really:Of course it lacks error handling code, but generally that's all there is.Code:#include <fstream> using namespace std; void copy(const char* from, const char* to) { ifstream in(from); ofstream out(to); out << in.rdbuf(); in.close(); out.close(); } int main() { copy("myfile1.txt", "myfile2.txt"); }
- lmov