You can handle this rather easily if you treat cout as a generic std::ofstream&.
IE
Code:
#include <iostream>
#include <fstream>
int main(int argc, char* argv[]) {
std::ostream& outStream = std::cout;
std::istream in;
std::ofstream outFile;
// handle args
if (/* output redirection needed */) {
outFile.open(/* appropriate name */);
outStream = outFile;
}
// else outStream will still be cout
// output stuff through outStream
}
This way, you don't have to write two different methods for when you are using different output streams.