Turn file management into C++ style

fopen_s wasn't portable, and fopen gave rise to an error in Visual
Studio. ifstream just works