"流" [英] "streams"

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

问题描述

我有一个关于C'的抽象流的问题。 (我似乎无法通过阅读几个教程来完全理解。)


Streams似乎建议输入可以连续处理如果

需要。这是真的吗?


据我所知,我只能得到一个流的流。当有一个

''\ r''。此时''\ r''变成''\ n'',整个

流被发送到一些现在只能访问我的

程序(同时,其他数据仍然堆积在流的输入区域,等待另一个''\ r''释放它们 -

允许它们流动。


这是对C'模型的准确观察吗?无论如何我可以

获得更多的连续流动作,而不是这个''\ r''触发

流?我猜可能有,但它会是一个

C-extension!?!?

顺便说一句,在K& R2中使用getchar的前几个例子依赖

比较(c = getchar())和EOF。但是,最终''\ r''

发生了什么,实际上从它的输入暂存区域释放了EOF?那个

''\ r''在那里等待释放下一个来自流的

输入的字符?是''\ r''被转换为''\ n''并发送到

它是否可以通过输入函数立即读取?这是因为与EOF的某些关系而消失了吗?

我们将非常感谢全面教程的链接。

解决方案

" Kobu" < KO ******** @ gmail.com>在消息中写道

news:11 ********************* @ z14g2000cwz.googlegro ups.com ...

我有一个关于C'的抽象流的问题。 (我似乎无法通过阅读几个教程完全理解)。

Streams似乎表明,如果需要,输入可以不断处理。这是真的?


是的,从某种意义上说,i / o实现为

连续''流''字符。 (连续

可以通过错误条件或

''文件末尾'指示符中断)。

到目前为止我知道,我只能得到一个流流。当有一个
''\ r''。


否。字符流不需要包含特定的

值字符。 ''\''(或''\ n''等)只是另一个

字符。

此时''\ r ''变成''\ n'''


字符翻译(如果有的话)由特定的

实现定义(可能是最知名的)是'CR / LF''到/

形式''\ n''在DOS和Windows中的翻译)。另请注意,这个

''翻译''仅适用于以''text

mode''(默认值)打开的流。流以二进制模式打开。 (表示

,第二个参数为b的''fopen()'),渲染角色

,因为它们是由连接的设备传递的,没有''翻译''



和整个
流被发送到一些现在只能访问我的
程序的抽象区域(同时,其他数据仍然堆积在流的输入区域,等待另一个''\ r''释放它们 -
允许它们流动)。


你问的是'缓冲',这是由一个实现定义的。

例如许多/大多数系统将标准流''stdin''附加到键盘上,使用''line buffering'',其中数据不会发送到

程序直到例如按下输入或返回键。但是语言并不要求这个



这是对C'模型的准确观察吗?


不,这似乎是你对特定平台上特定实现的观察结果。这无疑是一种非常普遍的行为。

无论如何,我可以获得更多的连续流动作,而不是这个''\ r' '触发了流?


您要问的是非阻塞输入,这不是必需的语言。

(也禁止用语言)。

我猜可能有,但它会是一个C-extension!?!?




是的,库扩展是典型的方法在适用的平台上执行此操作

,例如'stdin''

附加到行缓冲键盘输入的那些。一个实现

或OS也可能提供一个设施(通过另一个扩展)来禁用

''线路缓冲''。检查你的编译器文档。


-Mike


Mike Wahler写道:

不可以。字符流不需要包含特定的
值字符。 ''\''(或''\ n''等)只是另一个
字符。




文本流由以下内容组成:线路,换行线终止。


-

pete




pete < PF ***** @ mindspring.com>在消息中写道

news:41 *********** @ mindspring.com ...

Mike Wahler写道:

否。字符流不需要包含特定的
值字符。 ''\''(或''\ n''等)只是另一个
字符。



文本流由行组成,它们是换行符。




我写''stream'',而不是''text stream''。


无论如何,以下摘录自9899表示

a文本流可能包含零个或多个换行符。


7.19.2 Streams


2文本流是一个有序的字符序列组成

到行中,每行由零个或多个字符组成

加上一个终止的换行符。最后一行

是否需要终止换行字符是实现 -

定义。


-Mike


I have a question about C''s abstract "streams" (that I can''t seem to
FULLY understand from reading several tutorials).

Streams seems to suggest that input can be treated continously if
needed. Is this true?

So far as I know, I can only get a stream to "flow" when there is a
''\r''. At that point the ''\r'' is turned into a ''\n'' and the whole
stream is sent to some abstract area that is now only accessible to my
programs (meanwhile, other data is still piling into the input
"staging" area of the stream, waiting for another ''\r'' to free them-
allow them to flow).

Is this an accurate observation of C''s model? Is there anyway I can
get more of a continuous stream action, instead of this ''\r'' triggered
stream? I am guessing there might be, but it would be a
C-extension!?!?
By the way, the first couple examples using getchar in K&R2 rely on
comparing (c=getchar()) with EOF. But, what happened to the final ''\r''
that actually releases the EOF from it''s input staging area? Does that
''\r'' stay there waiting to release the next char that comes to the
input to the stream? Does that ''\r'' get converted to ''\n'' and sent on
it''s way ready for immediate reading by an input function? Does that
''\n'' disappear because of some relationship with EOF?
A link to comprehensive tutorials will be appreciated.

解决方案

"Kobu" <ko********@gmail.com> wrote in message
news:11*********************@z14g2000cwz.googlegro ups.com...

I have a question about C''s abstract "streams" (that I can''t seem to
FULLY understand from reading several tutorials).

Streams seems to suggest that input can be treated continously if
needed. Is this true?
Yes, in the sense that i/o is implemented as a
continuous ''stream'' of characters. ("continous"
being interruptible by an error condition or an
''end of file'' indicator).
So far as I know, I can only get a stream to "flow" when there is a
''\r''.
No. A stream of characters need not contain a particular
value character. ''\r'' (or ''\n'', etc.) is just another
character.
At that point the ''\r'' is turned into a ''\n''
Character translations (if any) are defined by a particular
implementation (probably most well known is the ''CR/LF'' to/
form ''\n'' translation in DOS and Windows). Also note that this
''translation'' is only applicable to streams opened with ''text
mode'' (the default). Streams open in "binary mode" (expressed
with second argument to ''fopen()'' of "b"), render the characters
as they are delivered by the attached device, with no ''translations''
at all.
and the whole
stream is sent to some abstract area that is now only accessible to my
programs (meanwhile, other data is still piling into the input
"staging" area of the stream, waiting for another ''\r'' to free them-
allow them to flow).
You''re asking about ''buffering'', which is defined by an implementation.
E.g. many/most systems where the standard stream ''stdin'' is attached
to a keyboard, use ''line buffering'', where the data is not sent to
the program until e.g. an ''Enter'' or ''return'' key is pressed. But this
is not required by the language.

Is this an accurate observation of C''s model?
No, it seems to be your observation of a particular implementation
of C on a particular platform. This is admittedly a very common
behavior.
Is there anyway I can
get more of a continuous stream action, instead of this ''\r'' triggered
stream?
You''re asking about ''nonblocking input'', which is not required
(nor prohibited) by the language.
I am guessing there might be, but it would be a
C-extension!?!?



Yes, library extensions are the typical method for doing this
on platforms where it''s applicable, e.g. those where ''stdin''
is attached to a line-buffered keyboard input. An implementation
or OS might also provide a facility (via another extension) to disable
''line buffering''. Check your compiler documentation.

-Mike


Mike Wahler wrote:

No. A stream of characters need not contain a particular
value character. ''\r'' (or ''\n'', etc.) is just another
character.



Text streams are composed of lines, which are newline terminated.

--
pete



"pete" <pf*****@mindspring.com> wrote in message
news:41***********@mindspring.com...

Mike Wahler wrote:

No. A stream of characters need not contain a particular
value character. ''\r'' (or ''\n'', etc.) is just another
character.



Text streams are composed of lines, which are newline terminated.



I wrote ''stream'', not ''text stream''.

Anyway, the below excerpt from 9899 indicates to me that
a text stream may contain zero or more newline characters.

7.19.2 Streams

2 A text stream is an ordered sequence of characters composed
into lines, each line consisting of zero or more characters
plus a terminating new-line character. Whether the last line
requires a terminating new-line character is implementation-
defined.

-Mike


这篇关于&QUOT;流&QUOT;的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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