When do you use fopen instead of open?
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.
加载中,请稍侯......
精彩评论