diff --git a/include/rfl/io/save_string.hpp b/include/rfl/io/save_string.hpp index 8b19198d..17ee1433 100644 --- a/include/rfl/io/save_string.hpp +++ b/include/rfl/io/save_string.hpp @@ -14,10 +14,10 @@ Result save_string(const std::string& _fname, const T& _obj, const WriteFunction& _write) { try { std::ofstream outfile; + outfile.open(_fname); if (!outfile.is_open()) { return error("Unable to open file '" + _fname + "' for writing."); } - outfile.open(_fname); _write(_obj, outfile); outfile.close(); } catch (std::exception& e) {