fopen()与open() [英] fopen() vs. open()

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

问题描述

我知道open()返回一个文件描述符,fopen()向FILE返回一个指针

。问题是,我何时使用fopen(),何时使用

open()?有人可以给我一个例子,在

其他时间使用一个吗?

I know open() returns a file descriptor and fopen() returns a pointer
to FILE. The question is, when do I use fopen() and when do I use
open()? Could someone give me an example when to use one over the
other?

推荐答案

2004年9月29日21:33 :57 -0700, cd*****@yahoo.com (Grocery Clerk)写道

。在comp.lang.c中:
On 29 Sep 2004 21:33:57 -0700, cd*****@yahoo.com (Grocery Clerk) wrote
in comp.lang.c:
我知道open()返回一个文件描述符,fopen()返回一个指向
open()?有人可以给我一个例子,在
其他地方使用一个吗?
I know open() returns a file descriptor and fopen() returns a pointer
to FILE. The question is, when do I use fopen() and when do I use
open()? Could someone give me an example when to use one over the
other?



fopen()和类型FILE *是标准C库的一部分,

可用于每个托管实现。


open()和文件描述符不属于标准C.它们是

非 - 系统提供的标准扩展,就C

语言而言。


因此,如果你想编写标准的可移植C代码,请使用fopen ()。


-

Jack Klein

主页: http://JK-Technology.Com

常见问题解答

comp.lang.c < a rel =nofollowhref =http://www.eskimo.com/~scs/C-faq/top.htmltarget =_ blank> http://www.eskimo.com/~scs/C -faq / top.html

comp.lang.c ++ http://www.parashift.com/c++-faq-lite/

alt.comp.lang.learn。 c-c ++
http: //www.contrib.andrew.cmu.edu/~a...FAQ-acllc.html



fopen() and the type FILE * are part of the standard C library,
available on every hosted implementation.

open() and file descriptors are not part of standard C. They are
non-standard extensions provided by your system, as far as the C
language is concerned.

So if you want to write standard portable C code, use fopen().

--
Jack Klein
Home: http://JK-Technology.Com
FAQs for
comp.lang.c http://www.eskimo.com/~scs/C-faq/top.html
comp.lang.c++ http://www.parashift.com/c++-faq-lite/
alt.comp.lang.learn.c-c++
http://www.contrib.andrew.cmu.edu/~a...FAQ-acllc.html


cd ***** @ yahoo.com (Grocery Clerk)写道:
cd*****@yahoo.com (Grocery Clerk) writes:
我知道open()返回文件描述符和fopen( )向FILE返回一个指针
。问题是,我何时使用fopen(),何时使用
open()?有人可以给我一个例子,在
其他地方使用一个吗?
I know open() returns a file descriptor and fopen() returns a pointer
to FILE. The question is, when do I use fopen() and when do I use
open()? Could someone give me an example when to use one over the
other?




当你想编写可移植代码时使用fopen()。 open()函数

未在C标准中定义。


-

Keith Thompson(The_Other_Keith) ks *** @ mib.org < http://www.ghoti.net/~kst>

圣地亚哥超级计算机中心< *> < http://users.sdsc.edu/~kst>

我们必须做点什么。这是事情。因此,我们必须这样做。



Use fopen() when you want to write portable code. The open() function
is not defined in the C standard.

--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.


在星期四,2004-09-30 00:11 - 0500,Jack Klein写道:
On Thu, 2004-09-30 at 00:11 -0500, Jack Klein wrote:
On 2004年9月29日21:33:57 -0700, cd*****@yahoo.com (Grocery Clerk)写道< comp.lang.c中的br />:
On 29 Sep 2004 21:33:57 -0700, cd*****@yahoo.com (Grocery Clerk) wrote
in comp.lang.c:
我知道open()返回一个文件描述符,fopen()返回一个指向GILE的指针。问题是,我何时使用fopen(),何时使用
open()?有人可以给我一个例子,在
其他地方使用一个吗?
I know open() returns a file descriptor and fopen() returns a pointer
to FILE. The question is, when do I use fopen() and when do I use
open()? Could someone give me an example when to use one over the
other?



fopen()和类型FILE *是标准C库的一部分,
每个托管实现都可用。

open()和文件描述符不是标准C的一部分。它们是您的系统提供的非标准扩展,就C而言>语言。

所以如果你想编写标准的可移植C代码,请使用fopen()。



fopen() and the type FILE * are part of the standard C library,
available on every hosted implementation.

open() and file descriptors are not part of standard C. They are
non-standard extensions provided by your system, as far as the C
language is concerned.

So if you want to write standard portable C code, use fopen().




值得注意的是由fopen()返回的stdio文件是

(或可以)缓冲。因此,如果你想要缓冲的I / O,请使用fopen()。


Fredrik Tolf



It is also worth noting that stdio FILEs, as returned by fopen(), are
(or can be) buffered. Thus, if you want buffered I/O, use fopen().

Fredrik Tolf


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

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