开发者

When do you use fopen instead of open?

开发者 https://www.devze.com 2023-03-16 21:31 出处:网络
I don\'t find any difference开发者_如何学运维 through test. What\'s the key to decide on this?fopen is a portable interface that any C environment should provide. Also, its result is a buffered strea

I don't find any difference开发者_如何学运维 through test.

What's the key to decide on this?


fopen is a portable interface that any C environment should provide. Also, its result is a buffered stream (FILE*) that can be used with the convenient stdio functions.

open is a Unix/POSIX-specific interface. Its result is a bare (unbuffered) file descriptor, which has to be used with low-level system calls. It does allow some more fine-grained control over I/O (see the list of flags in the POSIX standard), so sometimes you might want to open a file and then perhaps fdopen it to get stdio and buffering.

0

精彩评论

暂无评论...
验证码 换一张
取 消