fopen和fclose?

扫码查看
本文介绍了fopen和fclose?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果fopen失败,是否需要调用fclose?


我看到这样的例子:

....

stream = fopen(...);

if(stream == NULL)

{

....

}

其他

{

....

}

fclose(stream);

....


根据我的理解,它应该是这样的:

....

stream = fopen(...);

if(stream == NULL)

{

....

}

其他

{

....

fclose(stream);

}

if fopen failed, does it necessary to call fclose?

I see an example like this:
....
stream = fopen(...);
if(stream == NULL)
{
....
}
else
{
....
}
fclose(stream);
....

By my understanding, it should like this:
....
stream = fopen(...);
if(stream == NULL)
{
....
}
else
{
....
fclose(stream);
}

推荐答案





你的方式更可取,恕我直言,但我认为要么是合法的。更好的是

可能会改为使用std :: fstream。 :-)


干杯! --M



Your way is preferable, IMHO, but I think either is legal. Better still
might be to use std::fstream instead. :-)

Cheers! --M





V



V


这篇关于fopen和fclose?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-05 17:45
查看更多