Why don't you just redirect the output on the command line by calling
Code:
myprog.exe dirname > results.txt
If you really want it done in code then there's plenty of either OS dependant ways or other methods using the standard library. Check out fstream here ... http://www.cplusplus.com/reference/i...ostream/write/