免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 4012 | 回复: 4
打印 上一主题 下一主题

[函数] fopen()的参数 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2009-09-29 13:55 |只看该作者 |倒序浏览
参数有w+,w+b, wb+
它的解释是:使文件为0,长,或为读和写而打开。

我有些疑惑:符号+有什么意思?
还有w+b和wb+有什么区别?

论坛徽章:
0
2 [报告]
发表于 2009-09-29 14:20 |只看该作者
lz可以看看下面页面的说明:
http://www.cplusplus.com/reference/clibrary/cstdio/fopen/

For the modes where both read and writing (or appending) are allowed (those which include a "+" sign) ...blablabla...

论坛徽章:
0
3 [报告]
发表于 2009-09-29 16:12 |只看该作者
还挺详细的,多谢ls的
mode
C string containing a file access modes. It can be:
"r" Open a file for reading. The file must exist.
"w" Create an empty file for writing. If a file with the same name already exists its content is erased and the file is treated as a new empty file.  
"a" Append to a file. Writing operations append data at the end of the file. The file is created if it does not exist.
"r+" Open a file for update both reading and writing. The file must exist.
"w+" Create an empty file for both reading and writing. If a file with the same name already exists its content is erased and the file is treated as a new empty file.
"a+" Open a file for reading and appending. All writing operations are performed at the end of the file, protecting the previous content to be overwritten. You can reposition (fseek, rewind) the internal pointer to anywhere in the file for reading, but writing operations will move it back to the end of file. The file is created if it does not exist.

论坛徽章:
0
4 [报告]
发表于 2009-09-29 16:22 |只看该作者
This additional "b" character can either be appended at the end of the string (thus making the following compound modes: "rb", "wb", "ab", "r+b", "w+b", "a+b") or be inserted between the letter and the "+" sign for the mixed modes ("rb+", "wb+", "ab+").

r+b和rb+
w+b和wb+
是一样的

论坛徽章:
0
5 [报告]
发表于 2009-09-29 19:28 |只看该作者
In order to open a file as a binary file, a "b" character has to be included in the mode string
原来这个b是指binary
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP