If you wanted to read an input from foo.in and write an output to foo.out, then here is how you would implement it in C++:
#include <cstdio>
#include <iostream>
int main() {
freopen("foo.in", "r", stdin);
freopen("foo.out", "w", stdout);
//after these two lines, you may now use "cin" and "cout" as you would regularly.
}