c - 'stream' 在 C 中是什么意思?

标签 c file stream terminology

我正在阅读“C Primer Plus”中处理文件、流和键盘输入的部分。作者将流的概念与文件联系起来,定义流如下:

Conceptually, the C program deals with a stream instead of directly with a file. A stream is an idealized flow of data to which the actual input or output is mapped. That means various kinds of input with differing properties are represented by streams with more uniform properties. The process of opening a file then becomes one of associating a stream with the file, and reading and writing take place via the stream



作者粗体字是什么意思?文件和流之间的联系是什么?

最佳答案

设计 C 的人想要一种统一的方式来连接不同的顺序数据源,如文件、套接字、键盘、USB 端口、打印机或其他任何东西。

所以他们设计了一个可以应用于所有这些的界面。此接口(interface)使用所有这些接口(interface)共有的属性。

为了更容易谈论可以通过接口(interface)使用的东西,他们给了这些东西一个通用名称,流。

使用相同接口(interface)的好处在于,可以使用相同的代码从文件中读取,就像从键盘或套接字中读取一样。

关于c - 'stream' 在 C 中是什么意思?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38652953/

相关文章:

c - 如何分析这个FIFO程序呢?

c - 虚拟区域到页面

c - Mcrypt 库将结果写入文件

Python文件读写

C:读取二进制文件输出零

c# - 使用自定义流 (IEnumerable<T>)

c - C中双向链表的初始化,指针

c - 字符串指针的子字符串指针

java - 无阻塞地原子读取 n 个字节

javascript - 为客户端(浏览器)PDF 生成分块和传输大量数据