fopen

FILE * fopen ( const char * filename, const char * mode );
其中,参数mode可取以下值:

"r"
read: Open file for input operations. The file must exist.

"w"
write: Create an empty file for output operations. If a file with the same name already exists, its contents are discarded and the file is treated as a new empty file.

"a"
append: Open file for output at the end of a file. Output operations always write data at the end of the file, expanding it. Repositioning operations (fseek, fsetpos, rewind) are ignored. The file is created if it does not exist.

"r+"
read/update: Open a file for update (both for input and output). The file must exist.

"w+"
write/update: Create an empty file and open it for update (both for input and output). If a file with the same name already exists its contents are discarded and the file is treated as a new empty file.

"a+"
append/update: Open a file for update (both for input and output) with all output operations writing data at the end of the file. Repositioning operations (fseek, fsetpos, rewind) affects the next input operations, but output operations move the position back to the end of file. The file is created if it does not exist.

需要注意的是,对于 ”a” 或 “a+”,fseek, fsetpos, rewind 等重新定准的函数都是无效的,所有新写入的数据均追加至文件末尾。

参考资料:

http://www.cplusplus.com/reference/cstdio/fopen/

fopen函数中的mode参数的更多相关文章

  1. linux中probe函数中传递的参数来源(上)

    点击打开链接 上一篇中,我们追踪了probe函数在何时调用,知道了满足什么条件会调用probe函数,但probe函数中传递的参数我们并不知道在何时定义,到底是谁定义的,反正不是我们在驱动中定义的(当然 ...

  2. fopen()函数中参数mode的取值

    FILE * fopen(const char * path,const char * mode); 参数mode字符串则代表着流形态. mode有下列几种形态字符串: r 打开只读文件,该文件必须存 ...

  3. C语言-一个fopen函数中未使用二进制模式(b)引发的血案

    转自:http://blog.csdn.net/hinyunsin/article/details/6401854 最近写了一个网络文件传输模块,为了让这个模块具有更好的移植性,我尽量使用C标准IO ...

  4. Python函数中如何定义参数

    一.位置参数:根据函数定义时的参数位置传递参数#形参和实参的个数必须一致def fun1(): print("运行结果") print("this is fun1(),n ...

  5. 从Win32程序中的主函数中获取命令行参数

    在标准C或者Win32控制台程序的main函数中,它们都有两个参数:"argc" 和 "argv",如下所示: int main(int argc, char ...

  6. python:函数中五花八门的参数形式(茴香豆的『回』字有四种写法)

    毫不夸张的说,python语言中关于函数参数的使用,是我见过最为灵活的,随便怎么玩都可以,本文以数学乘法为例,演示几种不同的传参形式: 一.默认参数 def multiply1(x, y): retu ...

  7. Python函数中的可变参数

    在Python函数中,还可以定义可变参数. 如:给定一组数字a,b,c……,请计算a2 + b2 + c2 + ……. 要定义出这个函数,我们必须确定输入的参数.由于参数个数不确定,我们首先想到可以把 ...

  8. C/C++函数中使用可变参数

    先说明可变参数是什么,先回顾一下C++里面的函数重载,如果重复给出如下声明: int func(); int func(int); int func(float); int func(int, int ...

  9. function(函数)中的动态参数

    我们可向函数传递动态参数,*args,**kwargs,首先我们来看*args,示例如下:     1.show(*args) def show(*args): print(args,type(arg ...

随机推荐

  1. JS 如何获取自定义属性

    <script>var testEle = document.getElementById("test"); testEle.setAttribute("de ...

  2. 树形DP 2415HDU

    Bribing FIPA Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Tota ...

  3. php操作redis常用方法

    1,connect 描述:实例连接到一个Redis. 参数:host: string,port: int 返回值:BOOL 成功返回:TRUE;失败返回:FALSE 示例: <?php $red ...

  4. get_client_ip()

    get_client_ip()获取ip地址,在开启IPv6协议的主机上会全部返回0.0.0.0原因是他会把ipv6地址认为是非法地址而转换成0.0.0.0,而ipv4地址在ipv6主机上用get_cl ...

  5. [JavaWeb基础] 015.Struts2 表单验证框架

    在web开发的过程中,我们经常要用到一些填写表单的操作,我们一般都要在提交表单信息的时候对表单的内容进行验证,struts2给我们提供了简单的实现接口,让我们可以很容易的对表单进行验证.下面讲解下最传 ...

  6. Spring boot Sample 003之spring-boot-configuration-properties

    一.环境 1.1.Idea 2020.1 1.2.JDK 1.8 二.目的 通过properties文件配置spring boot 属性文件 三.步骤 3.1.点击File -> New Pro ...

  7. Beta冲刺 ——5.27

    这个作业属于哪个课程 软件工程 这个作业要求在哪里 Beta冲刺 这个作业的目标 Beta冲刺 作业正文 正文 github链接 项目地址 其他参考文献 无 一.会议内容 1.组员一起学习Git分支管 ...

  8. Rocket - diplomacy - LazyModule的实例化

    https://mp.weixin.qq.com/s/9PsBt4_4qHx4i6C5XtuiUw   介绍LazyModule和Node构造方法的执行过程,即实例化过程.     1. NullIn ...

  9. Rocket - config - Configs

    https://mp.weixin.qq.com/s/z2gUYuYQAHQCa_5HZcBszw   介绍各个配置项的组织方式.   参考链接: https://docs.qq.com/sheet/ ...

  10. 实现一个字符串匹配算法,从字符串 H 中,查找 是否存在字符串 Y ,若是存在返回所在位置的索引,不存在返回 -1(不基于indexOf/includes方法)

    /** 1.循环原始字符串的每一项,让每一项从当前位置向后截取 H.length 个字符, 然后和 Y 进行比较,如果不一样,继续循环:如果一样返回当前索引即可 **/ function myInde ...