If you're primarily using printf, open a file with fopen and write to it instead with fprintf().

If you're primarily using cout, open a an ofstream and write to it instead of cout.