Devo chiamare manualmente close()quando utilizzo un std::ifstream?
Ad esempio, nel codice:
std::string readContentsOfFile(std::string fileName) {
std::ifstream file(fileName.c_str());
if (file.good()) {
std::stringstream buffer;
buffer << file.rdbuf();
file.close();
return buffer.str();
}
throw std::runtime_exception("file not found");
}
Devo chiamare file.close()manualmente? Non dovresti ifstreamusare RAII per chiudere i file?