The easiest thing to do, and which doesn't require changing your program at all, is to redirect your program's output to a file when you run it:
MyProject.exe > file.txt
">" is a "redirection operator", as it is in many Unix shells.
If you're on Windows, you can read more about the output redirection operator and other such operators here. If you're using a Unix shell, use your shell's redirection operators (e.g., here's the Bash manual's advice).