C中的“流"是什么意思? [英] What does 'stream' mean in C?

查看:161
本文介绍了C中的“流"是什么意思?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在阅读"C Primer Plus"中的一节,其中涉及文件,流和键盘输入.作者将流与文件的概念联系起来,并按如下方式定义流:

从概念上讲,C程序处理流而不是直接处理文件. 流是实际输入或输出映射到的理想数据流.这意味着具有不同属性的各种输入由具有更统一属性的流表示.然后,打开文件的过程成为将流与文件相关联,并通过该流进行读写的过程之一.

作者用粗体字表示什么?文件和流之间的连接是什么?

解决方案

设计C的人们想要一种统一的方法来与顺序数据的不同来源进行接口,例如文件,套接字,键盘,USB端口,打印机等. >

因此,他们设计了一个可以应用于所有界面的界面.此接口使用所有属性共有的属性.

为了更轻松地讨论可以通过界面使用的事物,他们给事物赋予了通用名称​​ streams .

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

I'm reading a section in 'C Primer Plus' which deals with files, streams and keyboard input. The author connects the concept of stream with files and defines stream as follows:

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

What does the author mean by the bold sentence? And what is the connection between files and stream?

解决方案

The people designing C wanted a uniform way of interfacing with different sources of sequential data, like files, sockets, keyboards, USB ports, printers or whatever.

So they designed one interface that could be applied to all of them. This interface uses properties that are common to all of them.

To make it easier to talk about the things that could be used through the interface they gave the things a generic name, streams.

The beauty of using the same interface is that the same code can be used to read from a file as from the keyboard or a socket.

这篇关于C中的“流"是什么意思?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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