C++ Code Reorder Hard +35 XP
RAII File Handle
Arrange the RAII file handling pattern.
Click lines in the correct order
Available lines5 left
Your order
Click lines above to build your solution.
Show answer and explanation
Answer: {
ifstream file("input.txt");
if (!file.is_open()) return;
file << "data";
}
Open scope, create file object (RAII), validate, use, then auto-close when scope ends.
Hint: RAII: resource acquired in constructor, released in destructor.
What this challenge tests
Code Reorder in C++: raii, file-io.