There's a one liner for this:
std::ofstream outFile("file.out", std::ios::ate );
std::ifstream inFile( "file.in" );
std::copy(
(std::istreambuf_iterator<char>(inFile)), // (*)
std::istreambuf_iterator<char>(),
std::ostreambuf_iterator<char>(outFile)
);
(*) Extra pair of parentheses to prevent parsing this as function declaration.
For better performance you could read the file in chunks, using ifstream::read
and write them with ofstream::write
.