当前位置: 动力学知识库 > 问答 > 编程问答 >

c - What is the difference between a stream and a file?

问题描述:

Can anybody explain what exactly streams are, and how they relate to files?

网友答案:

In the context of the C Standard Library a stream is a generic interface for performing certain I/O operations. You can read from streams, write to streams, some streams are seekable. Opening a file as a stream is only one way to get a stream as an I/O interface for an application.

Other examples for I/O streams in C:

  • Standard Streams: http://linux.die.net/man/3/stdin
  • File Streams: http://linux.die.net/man/3/fopen
  • Pipes: http://linux.die.net/man/3/popen
  • Stream Sockets: http://linux.die.net/man/3/socket

For further reading, have a look at these:

  • http://www.gnu.org/software/libc/manual/html_mono/libc.html#I_002fO-Overview
  • http://www.gnu.org/software/libc/manual/html_mono/libc.html#I_002fO-on-Streams

Let me quote:

12.1 Streams

For historical reasons, the type of the C data structure that represents a stream is called FILE rather than “stream”. Since most of the library functions deal with objects of type FILE *, sometimes the term file pointer is also used to mean “stream”. This leads to unfortunate confusion over terminology in many books on C.

分享给朋友:
您可能感兴趣的文章:
随机阅读: