This is the code I have, but the file is a little smaller and doesn't execute:
int WriteFileContentsToNewFile(string inFilename, string outFilename)
{
ifstream infile(inFilename.c_str(), ios::binary);
ofstream outfile(outFilename.c_str(), ios::binary);
string line;
// Initial read
infile >> line;
outfile << line;
// Read the rest
while( infile )
{
infile >> line;
outfile << line;
}
infile.close();
outfile.close();
return 0;
}
What am I doing wrong? Is there a better way to read in the binary of an executable file and immediately write it out to another name? Any code examples?
I need to do it without a system copy in order to simulate writing to disk.