// Example 1: Closing a file after reading from it #includePackage library: The C++ File close function is part of the standard C++ library and is included in the `#include int main() { std::ifstream file("example.txt"); if (file.is_open()) { std::string line; while (getline(file, line)) { std::cout << line << std::endl; } file.close(); // Close the file after all lines have been read } else { std::cout << "Error opening file" << std::endl; } return 0; } // Example 2: Closing a file after writing to it #include #include int main() { std::ofstream file("example.txt"); if (file.is_open()) { file << "Hello, world!" << std::endl; file.close(); // Close the file after writing is complete } else { std::cout << "Error opening file" << std::endl; } return 0; }