If the fopen() succeeds (return value is not null) then presumably you then want to perform some operation on the file. For this you need to have a correctly set variable f to the file stream. Hence f = fopen() in L1 above.
note that this is C, not c++, which you may already know but once in a while someone uses C code inside C++ (valid to do) unknowingly.
all file operations including close should be done ONLY on a VALID file variable (open succeeded). You should close any file you successfully opened. Modern OS may do this for you when a program ends, but you must not assume this will happen.
if (argc != 2)
{
std::cerr << "usage:\n program.exe <your-file.txt>\n";
return 1;
}
std::string filename = argv[1];
std::ifstream f( filename );
if (!f)
{
std::cerr << "error: unable to open file \"" << filename << "\"\n";
return 1;
}
...
std::string s;
getline( f, s ); // read a line of text from `f`
...
// no need to worry about closing `f` — it is automatically managed
The ability to avoid jumping through the hoops C requires to safely read a line of text is reason enough to want to use C++.