system("./runmycode.out > output.txt"); [download]
In reply to Equivalence of System Call in C/C++ by Anonymous Monk