打开文件'A +'模式 [英] Opening a file in 'a+ 'mode

查看:266
本文介绍了打开文件'A +'模式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果一个文件是使用下面的命令打开

If a file is opened using the following command:

FILE *f1=fopen("test.dat","a+");

该名男子页上写着:

The man page reads:

A +

打开阅读和追加(在文件末尾写)。该
                    如果不存在,文件被创建。初始文件位置
                    读取是在文件的开头,但输出
                    总是附加到文件的末尾。

Open for reading and appending (writing at end of file). The file is created if it does not exist. The initial file position for reading is at the beginning of the file, but output is always appended to the end of the file.

也是如此 F1 有2个独立的偏移指针,一个用于读取和放大器;另写?

So does f1 have 2 separate offset pointers, one for read & another for write?

推荐答案

没有。

有只有一个指针最初是在文件的开始,但当写操作尝试它移动到文件末尾。您可以通过重新定位 fseek的退读取文件中的任何地方,但写操作将其移动回文件结尾。

There is just one pointer which initially is at the start of the file but when a write operation is attempted it is moved to the end of the file. You can reposition it using fseek or rewind anywhere in the file for reading, but writing operations will move it back to the end of file.

这篇关于打开文件'A +'模式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆