RAII (Resource Acquisition Is Initialization) means file streams close automatically when leaving scope. Declare them in functions or blocks, and they clean up on return or exception, no explicit close() needed.
This prevents resource leaks. If your function crashes before close(), the destructor still runs and flushes buffers. Manual close() is only needed when reusing streams or guaranteeing immediate flush.
Keep streams local when possible: { ifstream file("data.txt"); process(file); } closes automatically at brace. Global or long-lived streams hold files open unnecessarily.