would this be using ios::binary? since i will be copying *.exe so im wondering how it should be done... i dont want to use system since speed is an issue
would this be using ios::binary? since i will be copying *.exe so im wondering how it should be done... i dont want to use system since speed is an issue
i think so. if speed is really an issue, you could use a FILE* pointer from C.
does this look right? and can anyone explain to what this does line for line?Code:FILE *OriginalFile = fopen(Progname, "rb"); FILE *CopiedFile = fopen(RndWords, "wb"); int gk; while ((gk = fgetc(OriginalFile)) != EOF); fputc(gk, CopiedFile);
ok it copies the file but one file is 165kb big the orignal and the other is 1b big? what am i doing wrong?Code:#include <iostream.h> #include <stdio.h> #include <stdlib.h> int main() { FILE *OriginalFile = fopen("C:\\Microsoft Visual Studio\\compile files\\Debug\\filecopy.exe", "rb"); FILE *CopiedFile = fopen("C:\\Microsoft Visual Studio\\compile files\\copyfile.exe", "wb"); int gk; while ((gk = fgetc(OriginalFile)) != EOF); fputc(gk, CopiedFile); return (0); }
A search of the boards would give you a very informative thread with quite a few different methods. Here, I'll give you a little boost:
http://www.cprogramming.com/cboard/s...threadid=16157
It's in C, but all of the methods can be converted to C++ fairly easily.
-Prelude
My best code is written with the delete key.
> while ((gk = fgetc(OriginalFile)) != EOF);
Remove the ;
It means you do nothing until you reach the end of file, then you write a single char
For speed, you need to copy a block at a time, not a char
Eg.
Code:#include <stdio.h> int main ( ) { char buff[BUFSIZ]; FILE *in, *out; size_t n; in = fopen( "a.exe", "rb" ); out= fopen( "test.bin", "wb" ); while ( (n=fread(buff,1,BUFSIZ,in)) != 0 ) { fwrite( buff, 1, n, out ); } return 0; }
thank you salem and prelude your great!