I think you may have used the wrong function.
You should use freopen.
It takes three parameters: the file name as a string literal, what you want to do to the file, and the stream.
You can find more specific documentation here:
https://cplusplus.com/reference/cstdio/freopen/
For example, if you want to read input from a file called a.in:
freopen("a.in", "r", stdin);