I want to avoid using std::fopen
from <cstdlib>
as I've been warned that it's potentially unsafe.
There is nothing "unsafe" about fopen()
. It is part of the C++ standard by means of the C standard.
What they probably said is that using a RAII object is best to manage the resource (the file handle), in particular if you're using exceptions in your program.
I tried checking if there's a way to retrieve FILE*
from fstream
but it seems there isn't a way to do that.
Not an easy, completely portable one. See questions like this one.
If you really want a FILE*
, use the C API.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…