Если у вас есть только один входной файл и только один выходной файл, самый простой способ - использовать freopen:
#include <cstdio>
int main ()
{
freopen("input.txt","r",stdin);
freopen("output.txt", "w", stdout);
/* Now you can use cin/cout/scanf/printf as usual,
and they will read from the files specified above
instead of standard input/output */
int a, b;
scanf("%d%d", &a, &b);
printf("%d\n", a + b);
return 0;
}