How to use freopen and where can i use it?

Today…I came learnt abt freopen …so how and where can i use it ??

Suppose the question is this…

Problem Code:FLOW001
can i use…

in this ??

There are 2 ways of I/O in CP:

  1. Standard I/O: Use simple cin/cout to solve the problem.
  2. I/O using files: For examples, check this problem. The input is given using a file named “input.txt” and we have to write our output to a file named “output.txt”.
    We can deal with this scenario by writing following two lines
    inside of main() and the rest of the code remains unchanged.
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);