Problems with File I/O

I tried to use freopen() for File I/O. However there is a discrepancy with the module. The module says that you need the header file cstdio to use this method. I have attached a screenshot below:

But when I then use this, I get a compilation error. Furthermore, in the same module, the solution to the fence painting problem does not include the cstdio header file. I have shown the authors solution below:

When I use exactly the authors solutions but do include the header file, I get a whole host of errors to do with scope mostly.

So, I am not going to include the cstdio header file when using freopen() for File I/O.

So is the module wrong? (not the solution)

What errors are you seeing? What compiler are you using? Can you reproduce the error in some online IDE?

I checked two versions of C++ (Homebrew GCC 13.2.0, Apple clang version 14.0.3) and in both of them, including iostream automatically includes cstdio as well, and the code runs regardless of including cstdio or not. But it could be different for different compilers.

c++ - Does iostream includes functions of cstdio? - Stack Overflow.

I don’t see why including the header file was cause errors though.