面试题答案
一键面试#include <iostream>
#include <fstream>
class FileManager {
private:
std::fstream file;
public:
FileManager(const std::string& filename) {
file.open(filename, std::ios::in | std::ios::out);
if (!file.is_open()) {
throw std::runtime_error("Failed to open file");
}
}
~FileManager() {
if (file.is_open()) {
file.close();
}
}
};