流是什么意思?有什么特点? [英] What does stream mean? What are its characteristics?

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

问题描述

C ++ C#都使用 stream 一词来命名许多类。

C++ and C# both use the word stream to name many classes.


  • C ++ iostream istream ostream stringstream ostream_iterator istream_iterator ...

  • C# Stream FileStream MemoryStream BufferedStream ...

  • C++: iostream, istream, ostream, stringstream, ostream_iterator, istream_iterator...
  • C#: Stream, FileStream,MemoryStream, BufferedStream...

所以我很想知道, stream 是什么意思?
的特征是什么?
我什么时候可以用这个术语来命名我的班级?
这仅限于文件I / O类吗?

So it made me curious to know, what does stream mean? What are the characteristics of a stream? When can I use this term to name my classes? Is this limited to file I/O classes only?

有趣的是,到目前为止, C 不在任何地方使用此单词据我所知。

Interestingly, C doesn’t use this word anywhere, as far as I know.

推荐答案

许多数据结构(列表,集合等)都充当容器 -他们持有一组对象。但不是溪流;如果列表是一个桶,则流是一条软管。您可以从流中提取数据,也可以将数据推入流中-但通常仅一次,并且只能沿一个方向(当然也有例外)。例如,网络上的TCP数据就是流;您可以发送(或接收)大块数据,但只能与另一台计算机连接,并且通常只能发送一次-您不能倒带Internet。

Many data-structures (lists, collections, etc) act as containers - they hold a set of objects. But not a stream; if a list is a bucket, then a stream is a hose. You can pull data from a stream, or push data into a stream - but normally only once and only in one direction (there are exceptions of course). For example, TCP data over a network is a stream; you can send (or receive) chunks of data, but only in connection with the other computer, and usually only once - you can't rewind the Internet.

流可以还操纵通过它们的数据;压缩流,加密流等。但是,这里的隐喻是数据的软管。文件通常也以流的形式(在某种程度上)访问。您可以访问顺序数据块。当然,大多数文件系统还提供随机访问,因此流确实提供了诸如查找,位置,长度之类的内容-但并非所有实现都支持这种功能。寻找一些流或获取打开的套接字的长度没有任何意义。

Streams can also manipulate data passing through them; compression streams, encryption streams, etc. But again - the underlying metaphor here is a hose of data. A file is also generally accessed (at some level) as a stream; you can access blocks of sequential data. Of course, most file systems also provide random access, so streams do offer things like Seek, Position, Length etc - but not all implementations support such. It has no meaning to seek some streams, or get the length of an open socket.

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

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