This typically results from testing for the end of file incorrectly. You normally want to do something like:
while (infile>>variable) ...
or:
while (std::getline(infile, whatever)) ...
but NOT:
while (infile.good()) ...
or:
while (!infile.eof()) ...
Edit: The first two do a read, check whether it failed, and if so exit the loop. The latter two attempt a read, process what was "read", and then exit the loop on the next iteration if the previous attempt failed.
Edit2: to copy one file to another easily, consider using something like this:
// open the files:
ifstream readfile(inputFile);
ofstream writefile(outputFile);
// do the copy:
writefile << readfile.rdbuf();