【发布时间】:2018-02-24 01:47:21
【问题描述】:
正确吗?写:
try {
fstream file;
file.open(....);
f(x); // this function may throw an exception
...
file.close();
} catch {
...
}
我想知道如果try块内的函数抛出异常,文件是否会被关闭?
【问题讨论】:
-
是的,它会的,因为文件对象的析构函数会这样做。
-
顺便说一句,closure 意味着 C++ 中的其他东西 ...