fopen模式 [英] fopen modes

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

问题描述

r +和w +有真正的区别吗?我在我的手册页中读到r +

打开了一个文件进行读写,而w +打开了一个文件进行阅读和

写作,如果文件不存在的话会被创造出来。如果它存在它

将被截断。


比尔

Is there a real difference in r+ and w+ ? I read in my man pages that r+
opened a file for reading and writing while w+ opened a file for reading and
writing and if the file didn''t exist it would by created. If it existed it
would be truncated.

Bill

推荐答案

-----开始PGP签名消息-----

哈希:SHA1


Bill Cunningham写道:
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Bill Cunningham wrote:

r +和w +有真正的区别吗?我在我的手册页中读到r +

打开了一个文件进行读写,而w +打开了一个文件进行阅读和

写作,如果文件不存在的话会被创造出来。如果它存在它将会截断.b $ b将被截断。
Is there a real difference in r+ and w+ ? I read in my man pages that r+
opened a file for reading and writing while w+ opened a file for reading and
writing and if the file didn''t exist it would by created. If it existed it
would be truncated.



这就是区别。 r +不会截断文件,它只是打开它

并允许读写。与w +一起fopen总是返回一个句柄来获得具有读写权限的
空文件。


Pawel Dziepak

---- -BEGIN PGP SIGNATURE -----

版本:GnuPG v1.4.9(GNU / Linux)

评论:在Fedora中使用GnuPG - http://enigmail.mozdev.org

iEYEARECAAYFAkkPXncACgkQPFW + cUiIHNr6iACfZ0wkbBTvQQ Kyw / 8D4kPzDARp

wjMAoIxZbrkMTAY487oUXsqHp9dEwbpz

= iUvy

----- END PGP SIGNATURE -----

That''s the difference. r+ doesn''t truncate the file, it just opens it
and allows to read and write. fopen with w+ always returns a handle to
empty file with read and write privileges.

Pawel Dziepak
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.9 (GNU/Linux)
Comment: Using GnuPG with Fedora - http://enigmail.mozdev.org

iEYEARECAAYFAkkPXncACgkQPFW+cUiIHNr6iACfZ0wkbBTvQQ Kyw/8D4kPzDARp
wjMAoIxZbrkMTAY487oUXsqHp9dEwbpz
=iUvy
-----END PGP SIGNATURE-----


2008年11月3日15:14,在comp.lang.c中,Bill Cunningham

(no****@nspam.invalid)写道:
On November 3, 2008 15:14, in comp.lang.c, Bill Cunningham
(no****@nspam.invalid) wrote:

r +和w +有真正的区别吗?我在我的手册页中读到了

r +

打开了一个文件进行读写,而w +打开了一个文件供阅读

和写作,如果文件不存在它会被创建。如果它存在
,它将被截断。
Is there a real difference in r+ and w+ ? I read in my man pages that
r+
opened a file for reading and writing while w+ opened a file for reading
and writing and if the file didn''t exist it would by created. If it
existed it would be truncated.



比尔,问问自己这个......

"什么会fopen(" MyFile"," r +")如果文件MyFile,则返回/返回没有
存在吗?


现在,问问自己

"什么会fopen(MyFile," ; w +)如果文件MyFile,则返回/返回。没有

存在吗?


你的两个答案是否相同?如果不是,为什么不呢?


(提示:文档是否说r +会创建文件,如果它是
不存在吗?)


-

Lew Pitcher


Master Code代理& JOAT-in-training |已注册的Linux用户#112576
http://pitcher.digitalfreehold.ca/ |可根据要求提供GPG公钥

---------- Slackware - 因为我知道我在做什么。 ------

Bill, ask yourself this...
"What would fopen("MyFile","r+") do/return if the file "MyFile" didn''t
exist?

Now, ask yourself
"What would fopen("MyFile","w+") do/return if the file "MyFile" didn''t
exist?

Are your two answers the same? If not, why not?

(Hint: Does the documentation say that "r+" will create the file if it
doesn''t exist?)

--
Lew Pitcher

Master Codewright & JOAT-in-training | Registered Linux User #112576
http://pitcher.digitalfreehold.ca/ | GPG public key available by request
---------- Slackware - Because I know what I''m doing. ------




" Lew Pitcher" < lp ****** @ teksavvy.com写在留言中

新闻:c3 ************************ ** @ TEKSAVVY.COM ......

"Lew Pitcher" <lp******@teksavvy.comwrote in message
news:c3**************************@TEKSAVVY.COM...

(提示:文档是否说r +将创建文件,如果它是

不存在?)
(Hint: Does the documentation say that "r+" will create the file if it
doesn''t exist?)



我对我在posix系统上读到的文档的理解,没有

文件需要已经存在。


比尔

Too my understanding of the docs that I read on my posix system, no the
file needs to already exist.

Bill


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

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