this program must copy files but only txt files are copied correctly. When i try to copy .exe it is not copied or copied incorrectly. Please tell what am i doing wrong.
Thanks.
Hi,
One should use the macro EOF only to check the end of text files. As far as I understand it - but I am new to C and C++ - a binary file, depending on the OS, might contain many characters equal to EOF not only at its very end. To detect the end of a binary file you can either use the function feof(in) of the cstdio library, or within the fstream class the member function eof().
Also, and somebody should correct me if I am wrong, for the "fstream in", in.eof() is true only after an attempt to read beyond the eof has been done. Thus, it is wrong to say:
while(in.eof()){
c=in.get();
out.put(c)l
}
I rewrote you code with something I think sould also work on windows.
#include <fstream>
#include <iostream>
using namespace std;
int main (void ){
fstream in("input.bin",ios::binary|ios::in);
fstream out("output.bin",ios::binary|ios::out);