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. IntelliJ IDEA 2020.1 取消了auto-import自动导入

    Maven 和 Gradle 导入功能更新 v2020.1使得Maven和Gradle更改的导入不再繁琐.首先,我们删除了总是触发的自动导入,以及在更新完脚本之前不断显示并建议导入更新的提示框.取而代 ...

  2. Gym101630C Connections

    题目大意: 给出一个\(n\)个点\(m\)条边的有向图,无自环无重边.要求把这个图进行删边,直到只剩下\(2n\)条边,使得图中每个点都可以相互连通. 知识点: DFS 解题思路: 从点\(1\)出 ...

  3. 汉字统计(hdu2030)

    输入格式:一个整型,再循环带有空格的字符串 思考:用scanf_s()函数输入整型,然后一个大循环,再用gets_s()函数输入带空格的字符串. 注意:scanf_s()函数多加了%c,&d, ...

  4. Node.js NPM Tutorial

    Node.js NPM Tutorial – How to Get Started with NPM? NPM is the core of any application that is devel ...

  5. 组件-vue自定义方法传递

    组件样式 面包屑导航栏 js Vue.component('bannerOne', { created() { console.log(this.bigbackColor); }, props: { ...

  6. [wordpress使用]002_主题

    使用WordPress作为博客内容管理系统有一个很大的好处是,WordPress拥有大量的优秀的免费模板.你所需要的是下载安装,和稍作修改.下面接着开始WordPress教程:WordPress主题 ...

  7. [安卓基础] 005.创建一个简单的UI

    *:first-child { margin-top: 0 !important; } body > *:last-child { margin-bottom: 0 !important; } ...

  8. gopher 协议初探

    Gopher 协议初探 最近两天看到了字节脉搏实验室公众号上有一篇<Gopher协议与redis未授权访问>的文章,其中对gopher协议进行了比较详细的介绍,所以打算跟着后面复现学习一下 ...

  9. BUUCTF WEB

    BUUCTF 几道WEB题WP 今天做了几道Web题,记录一下,Web萌新写的不好,望大佬们见谅○| ̄|_ [RoarCTF 2019]Easy Calc 知识点:PHP的字符串解析特性 参考了一下网 ...

  10. & vue项目中的rem适配

    有个朋友问我在vue项目怎么做rem适配,我工作中都是用的dva,但是我感觉道理都是一样的,换汤不换药.配完就顺手写下来吧! 需要安装两个插件库 lib-flexible和px2rem-loader ...