c++ - How do I copy the binary code of an executable into a new file without using a system copy command? -


This is the code I have, but the file is a bit shorter and does not execute:

 < Code> int WriteFileContentsToNewFile (string infiline, string outfilename) {ifstream infile (inFilename.c_str (), IOS :: binary); Offream outfile (outFilename.c_str (), iOS :: binary); String line; // Initial Reading infile & gt; & Gt; Line; Outfile & lt; & Lt; Line; // Read the remaining time (infile) {infile> & Gt; Line; Outfile & lt; & Lt; Line; } Infile.close (); Outfile.close (); Return 0; }  

What am I doing wrong? Is there a better way to read the executable file in binary and write it to another name immediately? Examples of any code?

I need to do this without system copy for simulation writing on disk.

There is a way to use stream inserter for a streambuf:

  int WriteFileContentsToNewFile (string infiline, string outname name) {ifstream infile (inFilename.c_str (), iOS:: binary); Offream outfile (outFilename.c_str (), iOS :: binary); Outfile & lt; & Lt; Infile.rdbuf (); }  

Comments

Popular posts from this blog

oracle - The fastest way to check if some records in a database table? -

php - multilevel menu with multilevel array -

jQuery UI: Datepicker month format -