gpt4 book ai didi

c - 对文件的操作

转载 作者:行者123 更新时间:2023-11-30 20:14:45 25 4
gpt4 key购买 nike

我有一些文件,比如说一个文件夹中有大约 5 到 6 个文件,我必须以这样一种方式编写代码:我应该只使用一个 file_pointer 并一个接一个地读取所有文件,而不关闭它。阅读完所有文件后,我应该关闭。

我怎样才能实现这个目标?

最佳答案

fclose 是一个好习惯,但是(根据我对标准的理解)所有文件都会在程序退出时自动关闭。

来自标准:7.19.3 文件

If the main function returns to its original caller, or if the exit function is called, all open files are closed (hence all output streams are flushed) before program termination. Other paths to program termination, such as calling the abort function, need not close all files properly.

关于c - 对文件的操作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24676154/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com