什么是与 cin 和 cout 相关的“流”?

发布于 2024-08-01 15:52:28 字数 126 浏览 4 评论 0原文

一个教程正在讨论 cin 和 cout: “从语法上讲,这些流不用作函数:相反,使用运算符 <<(称为插入运算符)和 >>(称为提取运算符)将数据写入流或从流中读取数据。”

什么是“流”?

A tutorial is talking about cin and cout:
"Syntactically these streams are not used as functions: instead, data are written to streams or read from them using the operators <<, called the insertion operator and >>, called the extraction operator."

What is a 'stream'?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

紙鸢 2024-08-08 15:52:28

将“流”视为物理软管或管道。 在一端,有人可能会倒入一些水。在另一端,水就会出来。 这是对流的“读取”和“写入”。

流只是数据流动的地方。 它可以是“套接字流”(通过互联网)或“文件流”(到文件),或者可能是“内存流”,只是写入内存(RAM)中某个位置的数据。

Consider a "Stream" as a physical hose, or pipe. At one end, someone may pour some water in. At the other end, it will come out. This is 'reading' and 'writing' to the stream.

A stream is just a place where data goes. It can be a 'socket stream' (over the internet) or a 'file stream' (to a file), or perhaps a 'memory stream', just data written to a place in-memory (ram).

一城柳絮吹成雪 2024-08-08 15:52:28

“流”是代表数据源或可以写入数据的位置的对象。

示例包括文件句柄和管道 - 您可以从中读取数据或向其中写入数据。

流的一个重要属性是它们共享一个公共接口,因此相同的代码可以写入文件或管道(例如),而无需重写。

A "stream" is an object that represents a source of data, or a place where data can be written.

Examples include file handles and pipes - things that you can read data from or write data to.

An important property of streams is that they share a common interface, so the same code can write to either a file or a pipe (for instance) without needing to be rewritten.

你穿错了嫁妆 2024-08-08 15:52:28

您应该将流视为底层数据“源”或“汇”的抽象。 源是您从中读取数据的地方,而接收器是您向其写入数据的地方。

流的概念允许您在各种形式的媒体、网络连接、应用程序之间的管道、文件等上执行 I/O。

流抽象对于我们作为开发人员来说非常有价值,因为它允许我们简化输入和输出,并且它使我们能够灵活地安排和重新连接这些流的源和目的地。

一个很好的类比是软管。 您可以通过软管发送和接收数据,并且可以将这些软管连接到各种物体。

通过允许程序通过软管进行通信,我们允许各种程序相互通信,并且我们极大地提高了互操作性和实用性。

这是 UNIX 哲学的核心,并支持一些非常强大的编程习惯。

You should look at streams as abstractions on underlying 'sources' or 'sinks' of data. A source is something you read data from, and a sink is something you write data to.

The concept of streams allows you to perform I/O on various forms of media, network connections, pipes between applications, files, etc.

The stream abstraction is very valuable to us as developers as it allows us to simplify input and output, and it gives us the flexibility to arrange and reconnect the sources and destinations of these streams.

A good analogy is that of a hose. You can send and receive data through hoses, and you can connect these hoses to various things.

By allowing programs to talk through hoses, we allow all sorts of programs to talk to each other, and we increase interoperability and utility vastly.

This is at the heart of the UNIX philosophy, and supports some very powerful programming idioms.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文