RAII — resource management via object lifetime.
1class File {2 std::fstream f;3public:4 File(const std::string& path) {5 f.open(path);6 }7 ~File() {8 if (f.is_open()) f.close();9 }10};
Resource acquired in constructor, released in destructor.